Module: AttributesDSL
- Defined in:
- lib/attributes_dsl.rb,
lib/attributes_dsl/attribute.rb,
lib/attributes_dsl/attributes.rb,
lib/attributes_dsl/transprocs.rb
Overview
Simple DSL for PORO attributes
Defined Under Namespace
Modules: InstanceMethods, Transprocs 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.
- #inherited(klass) ⇒ Object
Class Method Details
.extended(klass) ⇒ Object
53 54 55 |
# File 'lib/attributes_dsl.rb', line 53 def self.extended(klass) klass.instance_eval { include InstanceMethods } end |
Instance Method Details
#attribute(name, options = {}, &coercer) ⇒ undefined
Retisters an attribute by name, options and coercer
47 48 49 50 |
# File 'lib/attributes_dsl.rb', line 47 def attribute(name, = {}, &coercer) @attributes = attributes.add(name, , &coercer) define_method(name) { attributes.fetch(name) } if attributes.reader? 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
24 25 26 |
# File 'lib/attributes_dsl.rb', line 24 def attributes @attributes ||= Attributes.new end |
#inherited(klass) ⇒ Object
58 59 60 |
# File 'lib/attributes_dsl.rb', line 58 def inherited(klass) klass.instance_variable_set(:@attributes, attributes) end |