Module: Modis::Attribute::ClassMethods

Defined in:
lib/modis/attribute.rb

Instance Method Summary collapse

Instance Method Details

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

Raises:



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

def attribute(name, type = :string, options = {})
  name = name.to_s
  raise AttributeError, "Attribute with name '#{name}' has already been specified." if attributes.key?(name)
  raise UnsupportedAttributeType, type unless TYPES.include?(type)

  attributes[name] = options.update(type: type)
  define_attribute_methods [name]
  class_eval "    def \#{name}\n      attributes['\#{name}']\n    end\n\n    def \#{name}=(value)\n      ensure_type('\#{name}', value)\n      \#{name}_will_change! unless value == attributes['\#{name}']\n      attributes['\#{name}'] = value\n    end\n  EOS\nend\n", __FILE__, __LINE__

#bootstrap_attributesObject



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

def bootstrap_attributes
  class << self
    attr_accessor :attributes
  end

  self.attributes = {}

  attribute :id, :integer
end