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

Class Method Summary collapse

Class Attribute Details

.configurationObject

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

Gets a value at a given configuration path, slash-separated

Returns: Target value or nil

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")    #=> nil


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

Check to see if a configuration has been defined.

Examples:

Abyss.configure do
  three do
    levels do
      deep do
        day "Monday"
      end
    end
  end
end

Abyss.has?("three/levels/deep/day") #=> true
Abyss.has?("non/existent/thing")    #=> false

Returns:

  • (Boolean)


37
38
39
# File 'lib/abyss.rb', line 37

def self.has?(path)
  get(path) ? true : false
end