Class: TrailGuide::Catalog
- Inherits:
-
Object
- Object
- TrailGuide::Catalog
show all
- Includes:
- Enumerable
- Defined in:
- lib/trail_guide/catalog.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(experiments = []) ⇒ Catalog
Returns a new instance of Catalog.
25
26
27
|
# File 'lib/trail_guide/catalog.rb', line 25
def initialize(experiments=[])
@experiments = experiments
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
62
63
64
65
|
# File 'lib/trail_guide/catalog.rb', line 62
def method_missing(meth, *args, &block)
return experiments.send(meth, *args, &block) if experiments.respond_to?(meth, true)
super
end
|
Instance Attribute Details
#experiments ⇒ Object
Returns the value of attribute experiments.
23
24
25
|
# File 'lib/trail_guide/catalog.rb', line 23
def experiments
@experiments
end
|
Class Method Details
.catalog ⇒ Object
6
7
8
|
# File 'lib/trail_guide/catalog.rb', line 6
def catalog
@catalog ||= new
end
|
.find(name) ⇒ Object
14
15
16
|
# File 'lib/trail_guide/catalog.rb', line 14
def find(name)
catalog.find(name)
end
|
.register(klass) ⇒ Object
10
11
12
|
# File 'lib/trail_guide/catalog.rb', line 10
def register(klass)
catalog.register(klass)
end
|
.select(name) ⇒ Object
18
19
20
|
# File 'lib/trail_guide/catalog.rb', line 18
def select(name)
catalog.select(name)
end
|
Instance Method Details
#each(&block) ⇒ Object
29
30
31
|
# File 'lib/trail_guide/catalog.rb', line 29
def each(&block)
experiments.each(&block)
end
|
#find(name) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/trail_guide/catalog.rb', line 33
def find(name)
if name.is_a?(Class)
experiments.find { |exp| exp == name }
else
experiments.find do |exp|
exp.experiment_name == name.to_s.underscore.to_sym ||
exp.metric == name.to_s.underscore.to_sym ||
exp.name == name.to_s.classify
end
end
end
|
#register(klass) ⇒ Object
57
58
59
60
|
# File 'lib/trail_guide/catalog.rb', line 57
def register(klass)
experiments << klass unless experiments.any? { |exp| exp == klass }
klass
end
|
#respond_to_missing?(meth, include_private = false) ⇒ Boolean
67
68
69
|
# File 'lib/trail_guide/catalog.rb', line 67
def respond_to_missing?(meth, include_private=false)
experiments.respond_to?(meth, include_private)
end
|
#select(name) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/trail_guide/catalog.rb', line 45
def select(name)
if name.is_a?(Class)
experiments.select { |exp| exp == name }
else
experiments.select do |exp|
exp.experiment_name == name.to_s.underscore.to_sym ||
exp.metric == name.to_s.underscore.to_sym ||
exp.name == name.to_s.classify
end
end
end
|