Method: Objectmancy::Objectable::ClassMethods#attribute
- Defined in:
- lib/objectmancy/objectable.rb
#attribute(name, **opts) ⇒ Object
Defines an attribute usable by Objectmancy to create your object. Only attributes defined with this method will be converted to attributes on the final object.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/objectmancy/objectable.rb', line 53 def attribute(name, **opts) symbolized_name = name.to_sym if registered_attributes.key? symbolized_name raise AttributeAlreadyDefinedError, name end if opts[:objectable] && opts[:type].nil? raise ArgumentError, ':objectable option reuqires :type option' end registered_attributes[symbolized_name] = AttributeOptions.new(opts) attr_accessor symbolized_name end |