Class: AppConfig::Storage::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/app_config/storage/base.rb

Direct Known Subclasses

Mongo, MySQL, Postgres, SQLite, YAML

Instance Method Summary collapse

Constructor Details

#initialize(options = nil) ⇒ Base

Returns a new instance of Base.



5
6
7
# File 'lib/app_config/storage/base.rb', line 5

def initialize(options = nil)
  @data = Storage::ConfigData.new(options)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object

Wrap ‘method_missing` to proxy to `@data`.



14
15
16
17
18
19
20
21
22
# File 'lib/app_config/storage/base.rb', line 14

def method_missing(name, *args)
  unless @data.nil?
    if name =~ /.+=$/  # Caller is a setter.
      @data.send(name.to_sym, *args[0])
    else
      @data.send(name.to_sym)
    end
  end
end

Instance Method Details

#to_hashObject



9
10
11
# File 'lib/app_config/storage/base.rb', line 9

def to_hash
  defined?(@data) ? @data.to_hash : Hash.new
end