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.
- #inherited(klass) ⇒ Object
Class Method Details
.extended(klass) ⇒ Object
60 61 62 63 |
# File 'lib/attributes_dsl.rb', line 60 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 |
#inherited(klass) ⇒ Object
66 67 68 |
# File 'lib/attributes_dsl.rb', line 66 def inherited(klass) klass.instance_variable_set(:@attributes, attributes) end |