Class: FactoryBot::Registry
- Inherits:
-
Object
- Object
- FactoryBot::Registry
- Includes:
- Enumerable
- Defined in:
- lib/factory_bot/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.
9 10 11 12 |
# File 'lib/factory_bot/registry.rb', line 9 def initialize(name) @name = name @items = ActiveSupport::HashWithIndifferentAccess.new end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/factory_bot/registry.rb', line 7 def name @name end |
Instance Method Details
#clear ⇒ Object
14 15 16 |
# File 'lib/factory_bot/registry.rb', line 14 def clear @items.clear end |
#each(&block) ⇒ Object
18 19 20 |
# File 'lib/factory_bot/registry.rb', line 18 def each(&block) @items.values.uniq.each(&block) end |
#find(name) ⇒ Object Also known as: []
22 23 24 25 26 |
# File 'lib/factory_bot/registry.rb', line 22 def find(name) @items.fetch(name) rescue KeyError => e raise (e) end |
#register(name, item) ⇒ Object
30 31 32 |
# File 'lib/factory_bot/registry.rb', line 30 def register(name, item) @items[name] = item end |
#registered?(name) ⇒ Boolean
34 35 36 |
# File 'lib/factory_bot/registry.rb', line 34 def registered?(name) @items.key?(name) end |