Class: DataMapper::Repository

Inherits:
Object
  • Object
show all
Includes:
Assertions, Migration, Transaction
Defined in:
lib/gems/dm-core-0.9.9/lib/dm-core/repository.rb,
lib/gems/dm-aggregates-0.9.9/lib/dm-aggregates/repository.rb

Defined Under Namespace

Modules: Migration, Transaction

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Transaction

#transaction

Methods included from Migration

#auto_migrate!, #auto_upgrade!, #map, #migrate!, #storage_exists?, #type_map

Methods included from Assertions

#assert_kind_of

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



22
23
24
# File 'lib/gems/dm-core-0.9.9/lib/dm-core/repository.rb', line 22

def name
  @name
end

Class Method Details

._load(marshalled) ⇒ Object



98
99
100
# File 'lib/gems/dm-core-0.9.9/lib/dm-core/repository.rb', line 98

def self._load(marshalled)
  new(marshalled.to_sym)
end

.adaptersAdapter

Returns the adapters registered for this repository.

Returns:

  • (Adapter)

    the adapters registered for this repository



10
11
12
# File 'lib/gems/dm-core-0.9.9/lib/dm-core/repository.rb', line 10

def self.adapters
  @adapters
end

.contextObject



14
15
16
# File 'lib/gems/dm-core-0.9.9/lib/dm-core/repository.rb', line 14

def self.context
  Thread.current[:dm_repository_contexts] ||= []
end

.default_nameObject



18
19
20
# File 'lib/gems/dm-core-0.9.9/lib/dm-core/repository.rb', line 18

def self.default_name
  :default
end

Instance Method Details

#_dumpObject



94
95
96
# File 'lib/gems/dm-core-0.9.9/lib/dm-core/repository.rb', line 94

def _dump(*)
  name.to_s
end

#adapterObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/gems/dm-core-0.9.9/lib/dm-core/repository.rb', line 24

def adapter
  # Make adapter instantiation lazy so we can defer repository setup until it's actually
  # needed. Do not remove this code.
  @adapter ||= begin
    raise ArgumentError, "Adapter not set: #{@name}. Did you forget to setup?" \
      unless self.class.adapters.has_key?(@name)

    self.class.adapters[@name]
  end
end

#aggregate(query) ⇒ Object



3
4
5
# File 'lib/gems/dm-aggregates-0.9.9/lib/dm-aggregates/repository.rb', line 3

def aggregate(query)
  adapter.aggregate(query)
end

#create(resources) ⇒ Object



50
51
52
# File 'lib/gems/dm-core-0.9.9/lib/dm-core/repository.rb', line 50

def create(resources)
  adapter.create(resources)
end

#delete(query) ⇒ Object



79
80
81
# File 'lib/gems/dm-core-0.9.9/lib/dm-core/repository.rb', line 79

def delete(query)
  adapter.delete(query)
end

#eql?(other) ⇒ Boolean Also known as: ==

Returns:



83
84
85
86
# File 'lib/gems/dm-core-0.9.9/lib/dm-core/repository.rb', line 83

def eql?(other)
  return true if super
  name == other.name
end

#identity_map(model) ⇒ Object



35
36
37
# File 'lib/gems/dm-core-0.9.9/lib/dm-core/repository.rb', line 35

def identity_map(model)
  @identity_maps[model] ||= IdentityMap.new
end

#read_many(query) ⇒ DataMapper::Collection

retrieve a collection of results of a query

Parameters:

  • query (Query)

    composition of the query to perform

Returns:

See Also:



60
61
62
# File 'lib/gems/dm-core-0.9.9/lib/dm-core/repository.rb', line 60

def read_many(query)
  adapter.read_many(query)
end

#read_one(query) ⇒ DataMapper::Resource, NilClass

retrieve a resource instance by a query

Parameters:

  • query (Query)

    composition of the query to perform

Returns:

  • (DataMapper::Resource)

    the first retrieved instance which matches the query

  • (NilClass)

    no object could be found which matches that query

See Also:



71
72
73
# File 'lib/gems/dm-core-0.9.9/lib/dm-core/repository.rb', line 71

def read_one(query)
  adapter.read_one(query)
end

#scopeObject

TODO: spec this



40
41
42
43
44
45
46
47
48
# File 'lib/gems/dm-core-0.9.9/lib/dm-core/repository.rb', line 40

def scope
  Repository.context << self

  begin
    return yield(self)
  ensure
    Repository.context.pop
  end
end

#to_sObject



90
91
92
# File 'lib/gems/dm-core-0.9.9/lib/dm-core/repository.rb', line 90

def to_s
  "#<DataMapper::Repository:#{@name}>"
end

#update(attributes, query) ⇒ Object



75
76
77
# File 'lib/gems/dm-core-0.9.9/lib/dm-core/repository.rb', line 75

def update(attributes, query)
  adapter.update(attributes, query)
end