Class: FactoryGirl::Registry
- Inherits:
-
Object
- Object
- FactoryGirl::Registry
- Includes:
- Enumerable
- Defined in:
- lib/factory_girl/registry.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #clear ⇒ Object
- #each(&block) ⇒ Object
- #find(name) ⇒ Object (also: #[])
-
#initialize(name) ⇒ Registry
constructor
A new instance of Registry.
- #register(name, item) ⇒ Object
- #registered?(name) ⇒ Boolean
Constructor Details
#initialize(name) ⇒ Registry
Returns a new instance of Registry.
7 8 9 10 |
# File 'lib/factory_girl/registry.rb', line 7 def initialize(name) @name = name @items = Decorator::ClassKeyHash.new({}) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/factory_girl/registry.rb', line 5 def name @name end |
Instance Method Details
#clear ⇒ Object
12 13 14 |
# File 'lib/factory_girl/registry.rb', line 12 def clear @items.clear end |
#each(&block) ⇒ Object
16 17 18 |
# File 'lib/factory_girl/registry.rb', line 16 def each(&block) @items.values.uniq.each(&block) end |
#find(name) ⇒ Object Also known as: []
20 21 22 23 24 25 26 |
# File 'lib/factory_girl/registry.rb', line 20 def find(name) if registered?(name) @items[name] else raise ArgumentError, "#{@name} not registered: #{name}" end end |
#register(name, item) ⇒ Object
30 31 32 |
# File 'lib/factory_girl/registry.rb', line 30 def register(name, item) @items[name] = item end |
#registered?(name) ⇒ Boolean
34 35 36 |
# File 'lib/factory_girl/registry.rb', line 34 def registered?(name) @items.key?(name) end |