Module: Modis::Attributes::ClassMethods

Defined in:
lib/modis/attributes.rb

Instance Method Summary collapse

Instance Method Details

#attribute(name, type = :string, options = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/modis/attributes.rb', line 24

def attribute(name, type = :string, options = {})
  name = name.to_s
  return if attributes.keys.include?(name)
  raise UnsupportedAttributeType.new(type) unless TYPES.include?(type)

  attributes[name] = options.update({ :type => type })
  define_attribute_methods [name]
  class_eval <<-EOS, __FILE__, __LINE__
    def #{name}
      attributes['#{name}']
    end

    def #{name}=(value)
      value = coerce_to_type('#{name}', value)
      #{name}_will_change! unless value == attributes['#{name}']
      attributes['#{name}'] = value
    end
  EOS
end

#bootstrap_attributesObject



14
15
16
17
18
19
20
21
22
# File 'lib/modis/attributes.rb', line 14

def bootstrap_attributes
  class << self
    attr_accessor :attributes
  end

  self.attributes = {}

  attribute :id, :integer
end