Module: CleanModel::Base::ClassMethods

Defined in:
lib/clean_model/base.rb

Instance Method Summary collapse

Instance Method Details

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



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/clean_model/base.rb', line 13

def attribute(name, options={})
  attr = Attribute.new(name, options)
  attributes << attr

  define_method name do
    instance_variable_get "@#{name}"
  end

  define_method "#{name}=" do |value|
    value = attr.transform(value)
    attr.validate!(value)
    instance_variable_set "@#{name}", value
  end
end

#attribute_namesObject



32
33
34
# File 'lib/clean_model/base.rb', line 32

def attribute_names
  attributes.map(&:name)
end

#attributesObject



28
29
30
# File 'lib/clean_model/base.rb', line 28

def attributes
  @attributes ||= []
end