Class: Render::Generator
- Inherits:
-
Object
- Object
- Render::Generator
- Defined in:
- lib/render/generator.rb
Constant Summary collapse
- FAUX_DATA_MAX =
1_000_000.freeze
Class Attribute Summary collapse
-
.instances ⇒ Object
Returns the value of attribute instances.
Instance Attribute Summary collapse
-
#algorithm ⇒ Object
Returns the value of attribute algorithm.
-
#matcher ⇒ Object
Returns the value of attribute matcher.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
-
.create!(type, matcher, algorithm) ⇒ Object
When in non-live mode, e.g.
- .find(type, to_match) ⇒ Object
- .trigger(type, to_match, algorithm_argument = nil) ⇒ Object
Instance Method Summary collapse
-
#initialize(type, matcher, algorithm) ⇒ Generator
constructor
A new instance of Generator.
- #trigger(algorithm_argument = nil) ⇒ Object
Constructor Details
#initialize(type, matcher, algorithm) ⇒ Generator
Returns a new instance of Generator.
47 48 49 50 51 |
# File 'lib/render/generator.rb', line 47 def initialize(type, matcher, algorithm) self.type = type self.matcher = matcher set_algorithm!(algorithm) end |
Class Attribute Details
.instances ⇒ Object
Returns the value of attribute instances.
15 16 17 |
# File 'lib/render/generator.rb', line 15 def instances @instances end |
Instance Attribute Details
#algorithm ⇒ Object
Returns the value of attribute algorithm.
45 46 47 |
# File 'lib/render/generator.rb', line 45 def algorithm @algorithm end |
#matcher ⇒ Object
Returns the value of attribute matcher.
45 46 47 |
# File 'lib/render/generator.rb', line 45 def matcher @matcher end |
#type ⇒ Object
Returns the value of attribute type.
45 46 47 |
# File 'lib/render/generator.rb', line 45 def type @type end |
Class Method Details
.create!(type, matcher, algorithm) ⇒ Object
When in non-live mode, e.g. testing, you can use custom generators to make fake data for a given attribute type and name-matcher.
22 23 24 25 26 |
# File 'lib/render/generator.rb', line 22 def create!(type, matcher, algorithm) generator = new(type, matcher, algorithm) instances.unshift(generator) generator end |
.find(type, to_match) ⇒ Object
38 39 40 41 42 |
# File 'lib/render/generator.rb', line 38 def find(type, to_match) instances.detect do |generator| (type == generator.type) && to_match.to_s.match(generator.matcher) end end |
.trigger(type, to_match, algorithm_argument = nil) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/render/generator.rb', line 28 def trigger(type, to_match, algorithm_argument = nil) generator = find(type, to_match) if generator generator.trigger(algorithm_argument) else Render.logger.warn("Could not find generator for type #{type} with matcher for #{to_match}, using nil") nil end end |
Instance Method Details
#trigger(algorithm_argument = nil) ⇒ Object
53 54 55 |
# File 'lib/render/generator.rb', line 53 def trigger(algorithm_argument = nil) algorithm[algorithm_argument] end |