Class: ValueSemantics::DSL

Inherits:
Object
  • Object
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

#initializeDSL

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

#__attributesObject (readonly)

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

Yields:

  • to the block containing the DSL

Returns:



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

#AnythingObject



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

#BoolObject



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

Returns:

  • (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