Class: ValueSemantics::DSL
- Inherits:
-
Object
- Object
- ValueSemantics::DSL
show all
- Defined in:
- lib/value_semantics.rb
Overview
Builds a Recipe via DSL methods
DSL blocks are instance_evald against an object of this class.
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ DSL
Returns a new instance of DSL.
277
278
279
|
# File 'lib/value_semantics.rb', line 277
def initialize
@__attributes = []
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
301
302
303
304
305
306
307
|
# File 'lib/value_semantics.rb', line 301
def method_missing(name, *args)
if respond_to_missing?(name)
def_attr(name, *args)
else
super
end
end
|
Instance Attribute Details
#__attributes ⇒ Object
Returns the value of attribute __attributes.
275
276
277
|
# File 'lib/value_semantics.rb', line 275
def __attributes
@__attributes
end
|
Class Method Details
.run { ... } ⇒ Recipe
Builds a Recipe from a DSL block
269
270
271
272
273
|
# File 'lib/value_semantics.rb', line 269
def self.run(&block)
dsl = new
dsl.instance_eval(&block)
Recipe.new(attributes: dsl.__attributes.freeze)
end
|
Instance Method Details
#Anything ⇒ Object
289
290
291
|
# File 'lib/value_semantics.rb', line 289
def Anything
Anything
end
|
#ArrayOf(element_validator) ⇒ Object
293
294
295
|
# File 'lib/value_semantics.rb', line 293
def ArrayOf(element_validator)
ArrayOf.new(element_validator)
end
|
#Bool ⇒ Object
281
282
283
|
# File 'lib/value_semantics.rb', line 281
def Bool
Bool
end
|
#def_attr(*args) ⇒ Object
297
298
299
|
# File 'lib/value_semantics.rb', line 297
def def_attr(*args)
__attributes << Attribute.define(*args)
end
|
#Either(*subvalidators) ⇒ Object
285
286
287
|
# File 'lib/value_semantics.rb', line 285
def Either(*subvalidators)
Either.new(subvalidators)
end
|
#respond_to_missing?(method_name, _include_private = nil) ⇒ Boolean
309
310
311
312
|
# File 'lib/value_semantics.rb', line 309
def respond_to_missing?(method_name, _include_private=nil)
first_letter = method_name.to_s.each_char.first
first_letter.eql?(first_letter.downcase)
end
|