module Silueta::ClassMethods

Public Instance Methods

attribute(attr, cast: nil) click to toggle source
# 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
attributes() click to toggle source
# File lib/silueta.rb, line 31
def attributes
  return @attributes ||= []
end
inherited(subclass) click to toggle source
# File lib/silueta.rb, line 9
def inherited(subclass)
  subclass.attributes.replace(attributes)
end