Module: BigIndex
- Extended by:
- Assertions
- Defined in:
- lib/big_index.rb,
lib/big_index/resource.rb,
lib/big_index/repository.rb,
lib/big_index/index_field.rb,
lib/big_index/support/assertions.rb,
lib/big_index/adapters/abstract_adapter.rb
Defined Under Namespace
Modules: Adapters, Assertions, Resource
Classes: IndexField, Repository
Class Method Summary
collapse
Methods included from Assertions
assert_kind_of
Class Method Details
.configurations ⇒ Object
58
59
60
|
# File 'lib/big_index.rb', line 58
def self.configurations
Repository.adapters || {}
end
|
.configurations=(configurations) ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/big_index.rb', line 62
def self.configurations=(configurations)
assert_kind_of 'configurations', configurations, Hash
Repository.clear_adapters
@configurations = symbolize_keys(configurations)
@configurations.each do |key, value|
assert_kind_of 'value', value, Hash
setup(key, value)
end
BigIndex::Repository.default_name = @configurations.keys[0] if @configurations.size == 1
end
|
.repository(name = nil) ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/big_index.rb', line 77
def self.repository(name = nil) current_repository = if name
raise ArgumentError, "First optional argument must be a Symbol, but was #{name.inspect}" unless name.is_a?(Symbol)
Repository.context.detect { |r| r.name == name } || Repository.new(name)
else
Repository.context.last || Repository.new(Repository.default_name)
end
if block_given?
current_repository.scope { |*block_args| yield(*block_args) }
else
current_repository
end
end
|
.root ⇒ Object
23
24
25
|
# File 'lib/big_index.rb', line 23
def self.root
@root ||= Pathname(__FILE__).dirname.parent.expand_path
end
|
.setup(name, options) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/big_index.rb', line 31
def self.setup(name, options)
assert_kind_of 'name', name, Symbol, String
assert_kind_of 'options', options, Hash
name = name.to_sym if name.is_a?(String)
adapter_name = options[:adapter].to_s
class_name = adapter_name.capitalize + 'Adapter'
unless Adapters::const_defined?(class_name)
lib_name = "#{adapter_name}_adapter"
begin
require root + 'lib' + 'big_index' + 'adapters' + lib_name
rescue LoadError => e
begin
require lib_name
rescue Exception
raise e
end
end
end
Repository.adapters[name] = Adapters::const_get(class_name).new(name, options)
end
|
.symbolize_keys(h) ⇒ Object
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/big_index.rb', line 92
def self.symbolize_keys(h)
config = {}
h.each do |k, v|
if k == 'port'
config[k.to_sym] = v.to_i
elsif v.is_a?(Hash)
config[k.to_sym] = symbolize_keys(v)
else
config[k.to_sym] = v
end
end
config
end
|
.vendor_root ⇒ Object
27
28
29
|
# File 'lib/big_index.rb', line 27
def self.vendor_root
@vendor_root ||= (Pathname(__FILE__).dirname.parent + "vendor").expand_path
end
|