Class: GOM::Storage::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/gom/storage/configuration.rb

Overview

Stores all information to configure a storage.

Defined Under Namespace

Modules: View

Constant Summary collapse

SCHEMA =
Configure::Schema.build{
  only :storage
  nested {
    storage {
      not_nil :name, :adapter
      nested {
        view {
          not_nil :name, :kind
        }
      }
    }
  }
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Configuration

Returns a new instance of Configuration.



25
26
27
28
# File 'lib/gom/storage/configuration.rb', line 25

def initialize(hash)
  @hash = { }
  hash.each{ |key, value| @hash[key.to_sym] = value }
end

Instance Attribute Details

#hashObject (readonly)

Returns the value of attribute hash.



23
24
25
# File 'lib/gom/storage/configuration.rb', line 23

def hash
  @hash
end

Instance Method Details

#[](key) ⇒ Object



51
52
53
# File 'lib/gom/storage/configuration.rb', line 51

def [](key)
  @hash[key.to_sym]
end

#adapterObject



43
44
45
# File 'lib/gom/storage/configuration.rb', line 43

def adapter
  @adapter ||= adapter_class.new self
end

#adapter_classObject



47
48
49
# File 'lib/gom/storage/configuration.rb', line 47

def adapter_class
  @adapter_class ||= GOM::Storage::Adapter[@hash[:adapter]] || raise(GOM::Storage::AdapterNotFoundError)
end

#nameObject



39
40
41
# File 'lib/gom/storage/configuration.rb', line 39

def name
  @hash[:name].to_s
end

#setupObject



30
31
32
# File 'lib/gom/storage/configuration.rb', line 30

def setup
  adapter.setup
end

#teardownObject



34
35
36
37
# File 'lib/gom/storage/configuration.rb', line 34

def teardown
  adapter.teardown
  clear_adapter
end

#values_at(*arguments) ⇒ Object



55
56
57
# File 'lib/gom/storage/configuration.rb', line 55

def values_at(*arguments)
  arguments.map{ |argument| self[argument] }
end

#viewsObject



59
60
61
62
63
64
65
66
67
68
# File 'lib/gom/storage/configuration.rb', line 59

def views
  @views ||= begin
    result = { }
    [ @hash[:view] ].flatten.compact.each do |hash|
      name = hash[:name]
      result[name.to_sym] = self.class.view hash
    end
    result
  end
end