Class: Juvet::Mapper

Inherits:
Object
  • Object
show all
Defined in:
lib/juvet/mapper.rb,
lib/juvet/mapper/collection.rb,
lib/juvet/mapper/mapped_repository.rb

Defined Under Namespace

Classes: Collection, MappedRepository

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Mapper

Returns a new instance of Mapper.



7
8
9
10
11
# File 'lib/juvet/mapper.rb', line 7

def initialize(&block)
  @collections = {}

  instance_eval(&block) if block_given?
end

Instance Attribute Details

#collectionsObject (readonly)

Returns the value of attribute collections.



5
6
7
# File 'lib/juvet/mapper.rb', line 5

def collections
  @collections
end

Instance Method Details

#build(adapter) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/juvet/mapper.rb', line 17

def build(adapter)
  collections.each_pair do |name, collection|
    if collection.repository && collection.repository.adapter == adapter.type
      adapter_instance = adapter.build.new collection, adapter.options
      collection.repository.klass.adapter = adapter_instance
    end
  end
end

#collection(name, &block) ⇒ Object



13
14
15
# File 'lib/juvet/mapper.rb', line 13

def collection(name, &block)
  collections[name] = Juvet::Mapper::Collection.new name, &block
end