Class: ValueSemantics::DSL
- Inherits:
-
Object
- Object
- ValueSemantics::DSL
- Defined in:
- lib/value_semantics.rb
Constant Summary collapse
- NOT_SPECIFIED =
Object.new
Instance Attribute Summary collapse
-
#__attributes ⇒ Object
readonly
Returns the value of attribute __attributes.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ DSL
constructor
A new instance of DSL.
- #method_missing(attr_name, validator = AnythingValidator, default: NOT_SPECIFIED, &coercion_block) ⇒ Object
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Constructor Details
#initialize ⇒ DSL
Returns a new instance of DSL.
135 136 137 |
# File 'lib/value_semantics.rb', line 135 def initialize @__attributes = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(attr_name, validator = AnythingValidator, default: NOT_SPECIFIED, &coercion_block) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/value_semantics.rb', line 139 def method_missing(attr_name, validator=AnythingValidator, default: NOT_SPECIFIED, &coercion_block) __attributes << Attribute.new( name: attr_name, has_default: default != NOT_SPECIFIED, default_value: default, validator: validator, coercer: coercion_block || IdentityCoercer, ) end |
Instance Attribute Details
#__attributes ⇒ Object (readonly)
Returns the value of attribute __attributes.
133 134 135 |
# File 'lib/value_semantics.rb', line 133 def __attributes @__attributes end |
Class Method Details
.run(&block) ⇒ Object
127 128 129 130 131 |
# File 'lib/value_semantics.rb', line 127 def self.run(&block) dsl = new dsl.instance_eval(&block) dsl.__attributes end |
Instance Method Details
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
151 152 153 |
# File 'lib/value_semantics.rb', line 151 def respond_to_missing?(method_name, include_private = false) true end |