Class: BigIndex::Repository

Inherits:
Object
  • Object
show all
Includes:
Assertions
Defined in:
lib/big_index/repository.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Assertions

#assert_kind_of

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



32
33
34
# File 'lib/big_index/repository.rb', line 32

def name
  @name
end

Class Method Details

.adaptersAdapter

Returns the adapters registered for this repository.

Returns:

  • (Adapter)

    the adapters registered for this repository



11
12
13
# File 'lib/big_index/repository.rb', line 11

def self.adapters
  @adapters
end

.clear_adaptersObject

TODO: Make sure this isn’t dangerous



28
29
30
# File 'lib/big_index/repository.rb', line 28

def self.clear_adapters
  @adapters = {}
end

.contextObject



15
16
17
# File 'lib/big_index/repository.rb', line 15

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

.default_nameObject



19
20
21
# File 'lib/big_index/repository.rb', line 19

def self.default_name
  @default_name ||= :default
end

.default_name=(name) ⇒ Object



23
24
25
# File 'lib/big_index/repository.rb', line 23

def self.default_name=(name)
  @default_name = name
end

Instance Method Details

#adapterObject



34
35
36
37
38
39
40
41
42
43
# File 'lib/big_index/repository.rb', line 34

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

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

Returns:

  • (Boolean)


56
57
58
59
# File 'lib/big_index/repository.rb', line 56

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

#scopeObject

TODO: spec this



46
47
48
49
50
51
52
53
54
# File 'lib/big_index/repository.rb', line 46

def scope
  Repository.context << self

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

#to_sObject



63
64
65
# File 'lib/big_index/repository.rb', line 63

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