Class: Quick::Sampler::DSL
- Inherits:
-
Object
- Object
- Quick::Sampler::DSL
- Includes:
- SimpleCombinators, SimpleValues
- Defined in:
- lib/quick/sampler/dsl.rb
Overview
A domain specific method for sampler definitions.
Instance methods of this class are available as barewords inside a sampler definition supplied as a block to compile.
Methods that produce a sampler actually wrap it in a Fluidiom instance that adds a fluid API to the sampler. This wrapping is stripped off from the sampler returned by compile - although I'm still undesided if that's the right thing to do.
(Incidentally, Fluidiom instances for deeper nested sub-samplers get leaked from compile at the moment)
Defined Under Namespace
Modules: SimpleCombinators, SimpleValues Classes: Fluidiom
Class Method Summary collapse
-
.compile(description: nil, &block) ⇒ Object
private
(see Quick::Sampler.compile).
Instance Method Summary collapse
-
#feed(enum = nil, &block) ⇒ Object
Sample an enumerable or block.
-
#initialize(binding = nil) ⇒ DSL
constructor
private
A new instance of DSL.
-
#inspect ⇒ Object
overloaded to display human readable text in tests output.
Methods included from SimpleCombinators
#combine, #hash_like, #list_like, #list_of, #merge, #object_like, #one_of, #one_of_weighted, #pick_from, #send_to
Methods included from SimpleValues
#boolean, #const, #fixnum, #integer, #negative_fixnum, #positive_fixnum, #probability, #string, #weighted_truth, #zero
Constructor Details
#initialize(binding = nil) ⇒ DSL
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.
Returns a new instance of DSL.
21 22 23 |
# File 'lib/quick/sampler/dsl.rb', line 21 def initialize binding = nil setup_delegation(binding) if binding end |
Class Method Details
.compile(description: nil, &block) ⇒ Object
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.
(see Quick::Sampler.compile)
27 28 29 30 31 |
# File 'lib/quick/sampler/dsl.rb', line 27 def self.compile description: nil, &block new(block.binding).instance_eval(&block).unwrap.tap do |sampler| sampler.description = description end end |
Instance Method Details
#feed(enum = nil, &block) ⇒ Object
Sample an enumerable or block
The block is ignored if enum
parameter isn't nil
45 46 47 48 |
# File 'lib/quick/sampler/dsl.rb', line 45 def feed enum = nil, &block enum ||= block if block_given? Fluidiom.new(Base.new(enum)) end |
#inspect ⇒ Object
overloaded to display human readable text in tests output
34 35 36 |
# File 'lib/quick/sampler/dsl.rb', line 34 def inspect "Quick Sampler DSL" end |