Class: Cobble::Fakes
Overview
A registry for procs that can be called to generate random, or fake, data.
Defined Under Namespace
Classes: Alias
Instance Attribute Summary collapse
-
#list ⇒ Object
List of all the fake procs in the system.
Class Method Summary collapse
Instance Method Summary collapse
-
#add(name, &block) ⇒ Object
Add a new proc to the system.
-
#alias(from, to) ⇒ Object
Create an alias from one fake proc to another.
-
#execute(name, *args) ⇒ Object
Executes the specified fake proc.
-
#initialize ⇒ Fakes
constructor
:nodoc:.
-
#reset! ⇒ Object
:nodoc:.
Constructor Details
#initialize ⇒ Fakes
:nodoc:
9 10 11 |
# File 'lib/cobble/fakes.rb', line 9 def initialize # :nodoc: self.reset! end |
Instance Attribute Details
#list ⇒ Object
List of all the fake procs in the system.
7 8 9 |
# File 'lib/cobble/fakes.rb', line 7 def list @list end |
Class Method Details
Instance Method Details
#add(name, &block) ⇒ Object
21 22 23 |
# File 'lib/cobble/fakes.rb', line 21 def add(name, &block) self.list[name.to_sym] = block end |
#alias(from, to) ⇒ Object
30 31 32 |
# File 'lib/cobble/fakes.rb', line 30 def alias(from, to) self.list[from.to_sym] = Cobble::Fakes::Alias.new(to) end |
#execute(name, *args) ⇒ Object
Executes the specified fake proc. Raise Cobble::Errors::NoFakeRegistered if the fake proc is not registered with the system.
Example:
Cobble::Fakes.execute(:email) # => '[email protected]'
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/cobble/fakes.rb', line 39 def execute(name, *args) block = self.list[name.to_sym] if block.is_a?(Cobble::Fakes::Alias) return execute(block.to, *args) end if block return block.call(*args) end raise Cobble::Errors::NoFakeRegistered.new(name) end |
#reset! ⇒ Object
:nodoc:
13 14 15 |
# File 'lib/cobble/fakes.rb', line 13 def reset! # :nodoc: self.list = {} end |