Module: Muffin::Attributes::ClassMethods
- Defined in:
- lib/muffin/frostings/attributes.rb
Instance Method Summary collapse
- #attribute(name, type = String, default: nil, array: nil, permit: nil, permitted_values: nil, &block) ⇒ Object
- #attributes ⇒ Object
- #introspect(name) ⇒ Object
Instance Method Details
#attribute(name, type = String, default: nil, array: nil, permit: nil, permitted_values: nil, &block) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/muffin/frostings/attributes.rb', line 9 def attribute(name, type = String, default: nil, array: nil, permit: nil, permitted_values: nil, &block) type = define_class name, block if block attributes[name] = Muffin::Attribute.new name: name, type: type, default: default, array: array, permit: permit, permitted_values: permitted_values, block: block define_method name do attributes && attributes[name] end define_method "#{name}=" do |value| @attributes ||= {} value = self.class.attributes[name].coercise(value) attributes[name] = value if permit_attribute!(name, value) end end |
#attributes ⇒ Object
22 23 24 |
# File 'lib/muffin/frostings/attributes.rb', line 22 def attributes @attributes ||= {} end |
#introspect(name) ⇒ Object
26 27 28 |
# File 'lib/muffin/frostings/attributes.rb', line 26 def introspect(name) attributes[name] end |