Class: Quick::Sampler::DSL

Inherits:
Object
  • Object
show all
Includes:
Config, 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

Instance Method Summary collapse

Methods included from SimpleCombinators

#list_like, #list_of, #one_of, #one_of_weighted, #pick_from, #send_to, #vector_of

Methods included from SimpleValues

#boolean, #const, #fixnum, #integer, #negative_fixnum, #positive_fixnum, #string, #zero

Methods included from Config

#config

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.

Parameters:

  • binding (Binding) (defaults to: nil)

    a context to lookup unknown methods



22
23
24
# File 'lib/quick/sampler/dsl.rb', line 22

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)



28
29
30
31
32
# File 'lib/quick/sampler/dsl.rb', line 28

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(&block) ⇒ Object

Wraps a block into a lazy enumerator which will become sampler.

I haven't decided yet if this is a private implementation detail or a powerful albeit confusing DSL verb

Yield Returns:

  • (<Sample>)

    a sampled value



46
47
48
# File 'lib/quick/sampler/dsl.rb', line 46

def feed &block
  Fluidiom.new(Base.new(block), config)
end

#inspectObject

overloaded to display human readable text in tests output



35
36
37
# File 'lib/quick/sampler/dsl.rb', line 35

def inspect
  "Quick Sampler DSL"
end