Class: Flotte::Registry::Base
- Inherits:
-
Object
- Object
- Flotte::Registry::Base
- Includes:
- Enumerable
- Defined in:
- lib/flotte/registry/base.rb
Instance Method Summary collapse
- #[](id) ⇒ Object
- #add(entity) ⇒ Object
- #all ⇒ Object
-
#initialize(entities = []) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(entities = []) ⇒ Base
Returns a new instance of Base.
8 9 10 11 12 13 |
# File 'lib/flotte/registry/base.rb', line 8 def initialize(entities = []) @entities_by_id = {} Array(entities).each do |entity| add(entity) end end |
Instance Method Details
#[](id) ⇒ Object
25 26 27 |
# File 'lib/flotte/registry/base.rb', line 25 def [](id) @entities_by_id[id] end |
#add(entity) ⇒ Object
15 16 17 18 19 |
# File 'lib/flotte/registry/base.rb', line 15 def add(entity) Array(entity).each do |entity| @entities_by_id[entity.id] = entity end end |
#all ⇒ Object
21 22 23 |
# File 'lib/flotte/registry/base.rb', line 21 def all @entities_by_id.values end |