Module: Abyss
- Defined in:
- lib/abyss.rb,
lib/abyss/store.rb,
lib/abyss/errors.rb,
lib/abyss/version.rb,
lib/abyss/deep_store.rb
Defined Under Namespace
Modules: Errors Classes: DeepStore, Store
Constant Summary collapse
- VERSION =
"0.4.0"
Class Attribute Summary collapse
-
.configuration ⇒ Object
Returns the value of attribute configuration.
Class Method Summary collapse
-
.configure(&block) ⇒ Object
Public interface to Abyss Configuragion API See Store for examples.
-
.get(path) ⇒ Object
Gets a value at a given configuration path, slash-separated.
-
.get!(path) ⇒ Object
Gets a value at a given configuration path, slash-separated.
-
.has?(path) ⇒ Boolean
Check to see if a configuration has been defined.
Class Attribute Details
.configuration ⇒ Object
Returns the value of attribute configuration.
9 10 11 |
# File 'lib/abyss.rb', line 9 def configuration @configuration end |
Class Method Details
.configure(&block) ⇒ Object
Public interface to Abyss Configuragion API See Store for examples.
15 16 17 18 |
# File 'lib/abyss.rb', line 15 def self.configure(&block) self.configuration ||= Store.new self.configuration.instance_eval &block end |
.get(path) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/abyss.rb', line 60 def self.get(path) path.split('/').inject(Abyss.configuration) do |acc, current_path_item| begin target = acc.send(current_path_item) return nil if target.nil? rescue NoMethodError return nil end target end end |
.get!(path) ⇒ Object
Gets a value at a given configuration path, slash-separated. This version raises an error if the value isn’t defined.
Returns: Target value
Examples:
Abyss.configure do
three do
levels do
deep do
day "Monday"
end
end
end
end
Abyss.get("three/levels/deep/day") #=> "Monday"
Abyss.has("non/existent/thing") # Raises Abyss::Errors::NotFound
92 93 94 |
# File 'lib/abyss.rb', line 92 def self.get!(path) get(path) || raise(Abyss::Errors::NotFound.new(path)) end |
.has?(path) ⇒ Boolean
37 38 39 |
# File 'lib/abyss.rb', line 37 def self.has?(path) get(path) ? true : false end |