Module: Lean::Attributes::ClassMethods
- Defined in:
- lib/lean-attributes/attributes/class_methods.rb
Overview
Methods that extend classes that include Lean::Attributes
Instance Method Summary collapse
-
#attribute(name, type, options = {}) ⇒ Attribute
Defines a new attribute.
-
#defined_attributes ⇒ Array<Symbol>
private
Names of defined attributes.
Instance Method Details
#attribute(name, type, options = {}) ⇒ Attribute
Defines a new attribute. Adds getter and setter methods to the class.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/lean-attributes/attributes/class_methods.rb', line 18 def attribute(name, type, = {}) attribute = Attribute.new( default: [:default], name: name, type: type ) defined_attributes << attribute.name class_eval(attribute.coercion_method, __FILE__, __LINE__ + 1) class_eval(attribute.getter_method, __FILE__, __LINE__ + 1) class_eval(attribute.setter_method, __FILE__, __LINE__ + 1) attribute end |
#defined_attributes ⇒ Array<Symbol>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns names of defined attributes.
38 39 40 41 42 43 44 45 46 |
# File 'lib/lean-attributes/attributes/class_methods.rb', line 38 def defined_attributes return @defined_attributes if @defined_attributes @defined_attributes = if superclass.respond_to?(:defined_attributes) superclass.defined_attributes.clone else [] end end |