Class: Dogfood::DSL::Evaluator::PoolProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/dogfood/dsl/evaluator.rb

Overview

Holds the shared rng so pool methods are callable without args in expressions: $poolpool.technicianspool.technicians.random, $poolpool.technicianspool.technicians.sample(2).

Instance Method Summary collapse

Constructor Details

#initialize(pool, rng) ⇒ PoolProxy

Returns a new instance of PoolProxy.



260
261
262
263
# File 'lib/dogfood/dsl/evaluator.rb', line 260

def initialize(pool, rng)
  @pool = pool
  @rng = rng
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *_args) ⇒ Object

Scoped view: $Dogfood::DSL::Evaluator::PoolProxy.poolpool.concernspool.concerns.brakespool.concerns.brakes.random

Raises:

  • (NoMethodError)


278
279
280
281
282
# File 'lib/dogfood/dsl/evaluator.rb', line 278

def method_missing(name, *_args)
  raise NoMethodError, "unknown pool method :#{name}" unless @pool.respond_to?(:category)

  CatProxy.new(@pool.category(name), @rng)
end

Instance Method Details

#allObject



273
274
275
# File 'lib/dogfood/dsl/evaluator.rb', line 273

def all
  @pool.all
end

#randomObject



265
266
267
# File 'lib/dogfood/dsl/evaluator.rb', line 265

def random
  @pool.random(@rng)
end

#respond_to_missing?(name, _include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


284
285
286
# File 'lib/dogfood/dsl/evaluator.rb', line 284

def respond_to_missing?(name, _include_private = false)
  @pool.respond_to?(:category) || super
end

#sample(count) ⇒ Object



269
270
271
# File 'lib/dogfood/dsl/evaluator.rb', line 269

def sample(count)
  @pool.sample(count, @rng)
end