Module: Silueta::ClassMethods

Defined in:
lib/silueta.rb

Instance Method Summary collapse

Instance Method Details

#attribute(attr, cast: nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/silueta.rb', line 13

def attribute(attr, cast: nil)
  attributes << attr

  if cast
    define_method(attr) do
      return cast.call(@attributes[attr])
    end
  else
    define_method(attr) do
      return @attributes[attr]
    end
  end

  define_method(:"#{attr}=") do |value|
    @attributes[attr] = value
  end
end

#attributesObject



31
32
33
# File 'lib/silueta.rb', line 31

def attributes
  return @attributes ||= []
end

#inherited(subclass) ⇒ Object



9
10
11
# File 'lib/silueta.rb', line 9

def inherited(subclass)
  subclass.attributes.replace(attributes)
end