Class: Dogfood::Pack

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

Constant Summary collapse

UnknownScenario =
Class.new(StandardError)

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) {|_self| ... } ⇒ Pack

Returns a new instance of Pack.

Yields:

  • (_self)

Yield Parameters:

  • _self (Dogfood::Pack)

    the object that the method was called on



13
14
15
16
17
18
19
20
21
# File 'lib/dogfood/pack.rb', line 13

def initialize(name)
  @name = name
  @step_modules = []
  @mixin_modules = []
  @pools = {}
  @delay_distributions = {}
  @scenarios = {}
  yield self if block_given?
end

Class Attribute Details

.currentObject

Returns the value of attribute current.



8
9
10
# File 'lib/dogfood/pack.rb', line 8

def current
  @current
end

Instance Attribute Details

#delay_distributionsObject (readonly)

Returns the value of attribute delay_distributions.



11
12
13
# File 'lib/dogfood/pack.rb', line 11

def delay_distributions
  @delay_distributions
end

#mixin_modulesObject (readonly)

Returns the value of attribute mixin_modules.



11
12
13
# File 'lib/dogfood/pack.rb', line 11

def mixin_modules
  @mixin_modules
end

#nameObject (readonly)

Returns the value of attribute name.



11
12
13
# File 'lib/dogfood/pack.rb', line 11

def name
  @name
end

#scenariosObject (readonly)

Returns the value of attribute scenarios.



11
12
13
# File 'lib/dogfood/pack.rb', line 11

def scenarios
  @scenarios
end

#step_modulesObject (readonly)

Returns the value of attribute step_modules.



11
12
13
# File 'lib/dogfood/pack.rb', line 11

def step_modules
  @step_modules
end

Instance Method Details

#add_pool(name, pool) ⇒ Object



36
37
38
# File 'lib/dogfood/pack.rb', line 36

def add_pool(name, pool)
  @pools[name.to_sym] = pool
end

#delays(hash) ⇒ Object



51
52
53
# File 'lib/dogfood/pack.rb', line 51

def delays(hash)
  @delay_distributions.merge!(hash)
end

#find_scenario(name) ⇒ Object



63
64
65
# File 'lib/dogfood/pack.rb', line 63

def find_scenario(name)
  @scenarios[name.to_sym] or raise UnknownScenario, "Unknown scenario: #{name}"
end

#include_mixins(*mods) ⇒ Object



27
28
29
# File 'lib/dogfood/pack.rb', line 27

def include_mixins(*mods)
  @mixin_modules.concat(mods)
end

#include_steps(*mods) ⇒ Object



23
24
25
# File 'lib/dogfood/pack.rb', line 23

def include_steps(*mods)
  @step_modules.concat(mods)
end

#load_dir(glob) ⇒ Object



67
68
69
# File 'lib/dogfood/pack.rb', line 67

def load_dir(glob)
  Dir[glob].each { |path| load_file(path) }
end

#load_file(path) ⇒ Object



71
72
73
74
75
76
77
78
79
# File 'lib/dogfood/pack.rb', line 71

def load_file(path)
  require "yaml"
  yaml = YAML.load_file(path)
  require_relative "dsl/schema"
  require_relative "dsl/compiler"
  Dogfood::DSL::Schema.validate!(yaml)
  klass = Dogfood::DSL::Compiler.compile(yaml, pack: self)
  register(yaml["name"].to_sym, klass)
end

#load_pool_file(path) ⇒ Object



40
41
42
43
44
45
# File 'lib/dogfood/pack.rb', line 40

def load_pool_file(path)
  require "yaml"
  yaml = YAML.load_file(path)
  Dogfood::DSL::PoolSchema.validate!(yaml)
  add_pool(yaml["name"], Dogfood::Pool.from_yaml(yaml["name"].to_sym, yaml))
end

#load_pools(dir) ⇒ Object



47
48
49
# File 'lib/dogfood/pack.rb', line 47

def load_pools(dir)
  Dir[File.join(dir, "*.yml")].sort.each { |path| load_pool_file(path) }
end

#pools(*mods) ⇒ Object



31
32
33
34
# File 'lib/dogfood/pack.rb', line 31

def pools(*mods)
  mods.each { |m| @pools[m.name.split("::").last.to_sym] = Dogfood::Pool.from_module(m) }
  @pools
end

#register(name, klass) ⇒ Object



55
56
57
# File 'lib/dogfood/pack.rb', line 55

def register(name, klass)
  @scenarios[name.to_sym] = klass
end

#scenario_keysObject



59
60
61
# File 'lib/dogfood/pack.rb', line 59

def scenario_keys
  @scenarios.keys
end