Class: Perpetuity::Configuration
- Inherits:
-
Object
- Object
- Perpetuity::Configuration
- Defined in:
- lib/perpetuity/config.rb
Class Method Summary collapse
Instance Method Summary collapse
- #adapter(name) ⇒ Object
- #data_source(*args) ⇒ Object
- #data_source_from_url(*args) ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #logger(*args) ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
6 7 8 9 |
# File 'lib/perpetuity/config.rb', line 6 def initialize @logger = Logger.new(STDOUT) @logger.progname = 'Perpetuity' end |
Class Method Details
.adapters ⇒ Object
61 62 63 |
# File 'lib/perpetuity/config.rb', line 61 def self.adapters @adapters ||= {} end |
Instance Method Details
#adapter(name) ⇒ Object
65 66 67 |
# File 'lib/perpetuity/config.rb', line 65 def adapter name self.class.adapters[name.to_sym] end |
#data_source(*args) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/perpetuity/config.rb', line 11 def data_source *args if args.any? db = args.first case db when String args[0] = URI(args[0]) @db = data_source_from_url(*args) when Symbol adapter = args.shift db_name = args.shift = args.shift || {} adapter_class = adapter(adapter) @db = adapter_class.new(.merge(db: db_name)) end end @db end |
#data_source_from_url(*args) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/perpetuity/config.rb', line 41 def data_source_from_url *args uri = args.shift = args.shift || {} protocol = uri.scheme klass = adapter(protocol) = { db: uri.path[1..-1], username: uri.user, password: uri.password, host: uri.host, port: uri.port, } if .key? :pool_size [:pool_size] = [:pool_size] end klass.new() end |
#logger(*args) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/perpetuity/config.rb', line 32 def logger *args if args.any? raise ArgumentError, 'Perpetuity::Configuration#logger takes 0..1 arguments' @logger = args.first end @logger end |