Class: GOM::Storage::Configuration
- Inherits:
-
Object
- Object
- GOM::Storage::Configuration
- 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
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #adapter ⇒ Object
- #adapter_class ⇒ Object
-
#initialize(hash) ⇒ Configuration
constructor
A new instance of Configuration.
- #name ⇒ Object
- #setup ⇒ Object
- #teardown ⇒ Object
- #values_at(*arguments) ⇒ Object
- #views ⇒ Object
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
#hash ⇒ Object (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 |
#adapter ⇒ Object
43 44 45 |
# File 'lib/gom/storage/configuration.rb', line 43 def adapter @adapter ||= adapter_class.new self end |
#adapter_class ⇒ Object
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 |
#name ⇒ Object
39 40 41 |
# File 'lib/gom/storage/configuration.rb', line 39 def name @hash[:name].to_s end |
#setup ⇒ Object
30 31 32 |
# File 'lib/gom/storage/configuration.rb', line 30 def setup adapter.setup end |
#teardown ⇒ Object
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 |
#views ⇒ Object
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 |