Module: ActiveWorker::Behavior::HasModes

Defined in:
lib/active_worker/behavior/has_modes.rb

Defined Under Namespace

Modules: ClassExtensions Classes: ModeNotSupportedException

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



23
24
25
26
27
# File 'lib/active_worker/behavior/has_modes.rb', line 23

def self.included(base)
  base.extend(ClassExtensions)
  base.template_field :mode
  base.before_save :set_mode_defined_fields
end

Instance Method Details

#set_mode_defined_fieldsObject



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/active_worker/behavior/has_modes.rb', line 29

def set_mode_defined_fields
  unless mode.nil? || mode.empty?
    if self.class.modes_map.supports? mode
      self.class.modes_map.mode(mode).each_pair do |field, value|
        write_attribute(field, value) unless read_attribute(field)
      end
    else
      raise ModeNotSupportedException, "Mode \"#{mode}\" not in Modes List: #{self.class.modes} for #{self.class}"
    end
  end
end