Module: MassiveRecord::ORM::AttributeMethods

Extended by:
ActiveSupport::Concern
Includes:
ActiveModel::AttributeMethods, ActiveModel::MassAssignmentSecurity
Defined in:
lib/massive_record/orm/attribute_methods/read.rb,
lib/massive_record/orm/attribute_methods/dirty.rb,
lib/massive_record/orm/attribute_methods/write.rb,
lib/massive_record/orm/attribute_methods/time_zone_conversion.rb,
lib/massive_record/orm/attribute_methods/cast_numbers_on_write.rb,
lib/massive_record/orm/attribute_methods.rb

Defined Under Namespace

Modules: CastNumbersOnWrite, ClassMethods, Dirty, Read, TimeZoneConversion, Write

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



59
60
61
62
63
64
65
66
# File 'lib/massive_record/orm/attribute_methods.rb', line 59

def method_missing(method, *args, &block)
  unless self.class.attribute_methods_generated?
    self.class.define_attribute_methods
    send(method, *args, &block)
  else
    super
  end
end

Instance Method Details

#attributesObject



33
34
35
# File 'lib/massive_record/orm/attribute_methods.rb', line 33

def attributes
  Hash[@attributes.collect { |attr_name, raw_value| [attr_name, read_attribute(attr_name)] }]
end

#attributes=(new_attributes) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/massive_record/orm/attribute_methods.rb', line 37

def attributes=(new_attributes)
  return unless new_attributes.is_a?(Hash)

  multiparameter_attributes = []

  sanitize_for_mass_assignment(new_attributes).each do |attr, value|
    if multiparameter? attr
      multiparameter_attributes << [attr, value]
    else
      writer_method = "#{attr}="
      if respond_to? writer_method
        send(writer_method, value)
      else
        raise UnknownAttributeError.new("Unkown attribute: #{attr}")
      end
    end
  end

  assign_multiparameter_attributes(multiparameter_attributes)
end

#respond_to?(*args) ⇒ Boolean

Returns:

  • (Boolean)


68
69
70
71
# File 'lib/massive_record/orm/attribute_methods.rb', line 68

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