module ActiveWorker::Expandable
Public Class Methods
included(base)
click to toggle source
# File lib/active_worker/expandable.rb, line 4 def self.included(base) base.template_field :number_of_threads, type: Integer, default: 1 base.template_field :number_of_workers, type: Integer, default: 1 base.belongs_to :thread_root_configuration, :polymorphic => true base.has_many :thread_expanded_configurations, :as => :thread_root_configuration, :class_name => 'ActiveWorker::Configuration', :autosave => true end
Public Instance Methods
configurations_for_events()
click to toggle source
# File lib/active_worker/expandable.rb, line 28 def configurations_for_events [self] + thread_expanded_configurations end
expand_for_threads()
click to toggle source
# File lib/active_worker/expandable.rb, line 14 def expand_for_threads maps = expansion_maps_for_threads maps[1..-1].each do |map_hash| map_hash[:thread_root_configuration_id] = id map_hash[:thread_root_configuration_type] = _type end expand_from_maps(maps) end
expand_for_workers()
click to toggle source
# File lib/active_worker/expandable.rb, line 23 def expand_for_workers maps = expansion_maps_for_workers expand_from_maps(maps) end
Private Instance Methods
create_for_expansion(options = {})
click to toggle source
# File lib/active_worker/expandable.rb, line 46 def create_for_expansion(options = {}) self.class.create(defined_fields.merge(parent_configuration: parent_configuration, root_object_id: root_object_id, root_object_type: root_object_type, renderable: false).merge(options)) end
expand_from_maps(maps)
click to toggle source
# File lib/active_worker/expandable.rb, line 34 def expand_from_maps(maps) first_config = true maps.map do |map_hash| if first_config first_config = false modify_for_expansion(map_hash) else create_for_expansion(map_hash) end end end
expansion_maps_for(number_of_configurations)
click to toggle source
# File lib/active_worker/expandable.rb, line 68 def expansion_maps_for(number_of_configurations) maps = [] number_of_configurations.times do maps << {} end maps end
expansion_maps_for_threads()
click to toggle source
# File lib/active_worker/expandable.rb, line 63 def expansion_maps_for_threads expansion_maps_for(number_of_threads) end
expansion_maps_for_workers()
click to toggle source
# File lib/active_worker/expandable.rb, line 59 def expansion_maps_for_workers expansion_maps_for(number_of_workers) end
modify_for_expansion(options = {})
click to toggle source
# File lib/active_worker/expandable.rb, line 53 def modify_for_expansion(options = {}) self.update_attributes!(options) self end