Class: EasySettings
- Inherits:
-
Hashie::Mash
- Object
- Hashie::Mash
- EasySettings
show all
- Defined in:
- lib/easy_settings.rb,
lib/easy_settings/rails.rb
Defined Under Namespace
Classes: Railtie
Constant Summary
collapse
- SourceFileNotExist =
Class.new(StandardError)
- DEFAULT_FILES =
%w(settings.yml config/settings.yml)
Class Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &blk) ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/easy_settings.rb', line 77
def method_missing(method_name, *args, &blk)
return self.[](method_name, &blk) if key?(method_name)
name, suffix = method_name_and_suffix(method_name)
case suffix
when "="
assign_property(name, args.first)
when "?"
!!self[name]
when "!"
initializing_reader(name)
when "_"
underbang_reader(name)
else
if !args[0].nil? || (args[1] && args[1][:nil])
assign_property(name, args.first)
else
self[method_name]
end
end
end
|
Class Attribute Details
.namespace ⇒ Object
Returns the value of attribute namespace.
11
12
13
|
# File 'lib/easy_settings.rb', line 11
def namespace
@namespace
end
|
.source_file ⇒ Object
Returns the value of attribute source_file.
11
12
13
|
# File 'lib/easy_settings.rb', line 11
def source_file
@source_file
end
|
.source_hash ⇒ Object
Returns the value of attribute source_hash.
11
12
13
|
# File 'lib/easy_settings.rb', line 11
def source_hash
@source_hash
end
|
Class Method Details
.[](key) ⇒ Object
27
28
29
|
# File 'lib/easy_settings.rb', line 27
def [](key)
instance[key]
end
|
.[]=(key, val) ⇒ Object
31
32
33
|
# File 'lib/easy_settings.rb', line 31
def []=(key, val)
instance[key] = val
end
|
.instance ⇒ Object
13
14
15
|
# File 'lib/easy_settings.rb', line 13
def instance
@instance ||= new(namespace ? _source[namespace] : _source)
end
|
.load! ⇒ Object
17
18
19
20
|
# File 'lib/easy_settings.rb', line 17
def load!
instance
true
end
|
.reload! ⇒ Object
22
23
24
25
|
# File 'lib/easy_settings.rb', line 22
def reload!
@instance = nil
load!
end
|
Instance Method Details
#assign_property(name, value) ⇒ Object
72
73
74
75
|
# File 'lib/easy_settings.rb', line 72
def assign_property(name, value)
super
self[name]
end
|