Class: Perpetuity::MapperRegistry
- Inherits:
-
Object
- Object
- Perpetuity::MapperRegistry
- Defined in:
- lib/perpetuity/mapper_registry.rb
Instance Method Summary collapse
- #[](klass) ⇒ Object
- #[]=(klass, mapper) ⇒ Object
- #has_mapper?(klass) ⇒ Boolean
-
#initialize ⇒ MapperRegistry
constructor
A new instance of MapperRegistry.
Constructor Details
#initialize ⇒ MapperRegistry
Returns a new instance of MapperRegistry.
3 4 5 |
# File 'lib/perpetuity/mapper_registry.rb', line 3 def initialize @mappers = Hash.new { |_, klass| raise KeyError, "No mapper for #{klass}" } end |
Instance Method Details
#[](klass) ⇒ Object
11 12 13 |
# File 'lib/perpetuity/mapper_registry.rb', line 11 def [] klass @mappers[klass].new(self) end |
#[]=(klass, mapper) ⇒ Object
15 16 17 |
# File 'lib/perpetuity/mapper_registry.rb', line 15 def []= klass, mapper @mappers[klass] = mapper end |
#has_mapper?(klass) ⇒ Boolean
7 8 9 |
# File 'lib/perpetuity/mapper_registry.rb', line 7 def has_mapper? klass @mappers.has_key? klass end |