Module: Armada::AttributeMethods

Extended by:
ActiveSupport::Concern
Includes:
ActiveModel::AttributeMethods
Included in:
Model
Defined in:
lib/armada/attribute_methods.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_id, *args, &block) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# File 'lib/armada/attribute_methods.rb', line 49

def method_missing(method_id, *args, &block)
  if !self.class.attribute_methods_generated?
    self.class.define_attribute_methods
    method_name = method_id.to_s
    guard_private_attribute_method!(method_name, args)
    send(method_id, *args, &block)
  else
    super
  end
end

Instance Method Details

#attributes=(attributes) ⇒ Object



44
45
46
47
# File 'lib/armada/attribute_methods.rb', line 44

def attributes=(attributes)
  attributes.each_pair { |k, v| send("#{k}=",v) }
  @attributes
end

#read_attribute(attribute_name) ⇒ Object



40
41
42
# File 'lib/armada/attribute_methods.rb', line 40

def read_attribute(attribute_name)
  @attributes[attribute_name]
end

#respond_to?(*args) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
63
# File 'lib/armada/attribute_methods.rb', line 60

def respond_to?(*args)
  self.class.define_attribute_methods
  super
end

#write_attribute(attribute_name, value) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/armada/attribute_methods.rb', line 31

def write_attribute(attribute_name, value)
  attribute_name = attribute_name.to_s
  if !persisted? || attribute_name != "id"
    @attributes[attribute_name] = value
  else
    @attributes["id"]
  end
end