Module: AirctiveRecord::AttributeMethods

Extended by:
ActiveSupport::Concern
Included in:
Base
Defined in:
lib/airctiverecord/attribute_methods.rb

Instance Method Summary collapse

Instance Method Details

#attribute_present?(attr_name) ⇒ Boolean

Returns:

  • (Boolean)


91
92
93
94
# File 'lib/airctiverecord/attribute_methods.rb', line 91

def attribute_present?(attr_name)
  value = read_attribute(attr_name)
  !value.nil? && !(value.respond_to?(:empty?) && value.empty?)
end

#attributesObject



69
# File 'lib/airctiverecord/attribute_methods.rb', line 69

def attributes = fields

#attributes=(attrs) ⇒ Object



71
72
73
74
75
76
77
78
79
# File 'lib/airctiverecord/attribute_methods.rb', line 71

def attributes=(attrs)
  attrs.each do |key, value|
    if respond_to?("#{key}=")
      send("#{key}=", value)
    else
      self[key.to_s] = value
    end
  end
end

#read_attribute(attr_name) ⇒ Object



81
82
83
84
# File 'lib/airctiverecord/attribute_methods.rb', line 81

def read_attribute(attr_name)
  field_name = self.class.field_mappings[attr_name.to_s] || attr_name.to_s
  self[field_name]
end

#write_attribute(attr_name, value) ⇒ Object



86
87
88
89
# File 'lib/airctiverecord/attribute_methods.rb', line 86

def write_attribute(attr_name, value)
  field_name = self.class.field_mappings[attr_name.to_s] || attr_name.to_s
  self[field_name] = value
end