Module: CouchbaseSettings
- Defined in:
- lib/couchbase-settings.rb,
lib/couchbase_settings/railtie.rb,
lib/couchbase_settings/version.rb
Defined Under Namespace
Classes: Railtie, UndefinedCouchbaseSettings
Constant Summary
collapse
- VERSION =
"0.3.4"
Class Method Summary
collapse
Class Method Details
.create_cbsettings_class(yml_file) ⇒ Object
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/couchbase-settings.rb', line 34
def create_cbsettings_class(yml_file)
hash = load_yml(yml_file)
klass_name = "CouchbaseSetting"
klass = Object.const_set(klass_name,Class.new)
hash.each do |key,value|
klass.define_singleton_method(key){ value }
end
klass.define_singleton_method("to_hash") { hash }
klass.class_eval do
def self.method_missing(method_id,*args)
raise UndefinedCouchbaseSettings, "#{method_id} is not defined in #{self.to_s}"
end
end
puts CouchbaseSetting.to_hash
end
|
.find_ymls ⇒ Object
28
29
30
31
32
|
# File 'lib/couchbase-settings.rb', line 28
def find_ymls
main_file = "#{Rails.root.to_s}/config/couchbase.yml"
couchbase_main_file = File.exists?(main_file) ? [main_file] : []
couchbase_main_file
end
|
.inspect ⇒ Object
24
25
26
|
# File 'lib/couchbase-settings.rb', line 24
def inspect
CouchbaseSetting.to_hash
end
|
.load_yml(yml_file) ⇒ Object
58
59
60
61
|
# File 'lib/couchbase-settings.rb', line 58
def load_yml(yml_file)
erb = ERB.new(File.read(yml_file)).result
erb.present? ? YAML.load(erb).to_hash[Rails.env] : {}
end
|
.setup! ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/couchbase-settings.rb', line 12
def setup!
puts "---------------------------------------------------"
puts "CouchbaseSetting loaded... (/config/couchbase.yml)"
find_ymls.each do |yml|
create_cbsettings_class(yml)
end
puts "---------------------------------------------------"
end
|