Module: AttributesDSL
- Defined in:
- lib/attributes_dsl.rb,
lib/attributes_dsl/attribute.rb,
lib/attributes_dsl/attributes.rb
Overview
Simple DSL for PORO attributes
Defined Under Namespace
Modules: InstanceMethods Classes: Attribute, Attributes
Class Method Summary collapse
Instance Method Summary collapse
-
#attribute(name, options = {}, &coercer) ⇒ undefined
Retisters an attribute by name, options and coercer.
-
#attributes ⇒ AttributeDSL::Attributes
private
The mutable collection of declared attributes.
-
#new(hash) ⇒ Object
Object contstructor that filters hash of attributes.
Class Method Details
.extended(klass) ⇒ Object
72 73 74 75 |
# File 'lib/attributes_dsl.rb', line 72 def self.extended(klass) # use __send__ for compatibility to 1.9.3 (where `.include` was private) klass.__send__(:include, InstanceMethods) end |
Instance Method Details
#attribute(name, options = {}, &coercer) ⇒ undefined
Retisters an attribute by name, options and coercer
52 53 54 55 56 57 |
# File 'lib/attributes_dsl.rb', line 52 def attribute(name, = {}, &coercer) s_name = name.to_sym @attributes = attributes.register(s_name, , &coercer) define_method(s_name) { attributes.fetch(s_name) } end |
#attributes ⇒ AttributeDSL::Attributes
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.
The mutable collection of declared attributes
23 24 25 |
# File 'lib/attributes_dsl.rb', line 23 def attributes @attributes ||= Attributes.new end |
#new(hash) ⇒ Object
Object contstructor that filters hash of attributes
67 68 69 |
# File 'lib/attributes_dsl.rb', line 67 def new(hash) super attributes.extract(hash) end |