Class: Bricolage::DataSourceFactory
- Inherits:
-
Object
- Object
- Bricolage::DataSourceFactory
- Defined in:
- lib/bricolage/datasource.rb
Defined Under Namespace
Classes: Loader
Constant Summary collapse
- DATA_SOURCE_FILE_NAME_1 =
'datasource.yml'- DATA_SOURCE_FILE_NAME_2 =
'database.yml'- PASSWORD_FILE_NAME =
'password.yml'- BUILTIN_TYPES =
%w(generic file ruby)
Class Method Summary collapse
Instance Method Summary collapse
-
#[](name) ⇒ Object
Ruby API.
-
#get(kind, name) ⇒ Object
For job classes.
-
#initialize(configs, context, logger) ⇒ DataSourceFactory
constructor
A new instance of DataSourceFactory.
Constructor Details
#initialize(configs, context, logger) ⇒ DataSourceFactory
Returns a new instance of DataSourceFactory.
53 54 55 56 57 |
# File 'lib/bricolage/datasource.rb', line 53 def initialize(configs, context, logger) @configs = configs @context = context @logger = logger end |
Class Method Details
.load(context, logger) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/bricolage/datasource.rb', line 14 def DataSourceFactory.load(context, logger) loader = Loader.new(context, logger) loader.load_passwords(PASSWORD_FILE_NAME) begin return loader.load(DATA_SOURCE_FILE_NAME_1) rescue DataSourceFileNotExist return loader.load(DATA_SOURCE_FILE_NAME_2) end end |
Instance Method Details
#[](name) ⇒ Object
Ruby API
73 74 75 76 77 78 79 80 |
# File 'lib/bricolage/datasource.rb', line 73 def [](name) if BUILTIN_TYPES.include?(name) return DataSource.new_for_type(name, name, {}, @context, @logger) end conf = config(name) type = conf.delete(:type) DataSource.new_for_type(type, name, conf, @context, @logger) end |
#get(kind, name) ⇒ Object
For job classes
62 63 64 65 66 67 68 69 70 |
# File 'lib/bricolage/datasource.rb', line 62 def get(kind, name) if BUILTIN_TYPES.include?(kind) return DataSource.new_for_type(kind, kind, {}, @context, @logger) end entry_name = name || kind conf = config(entry_name) type = conf.delete(:type) DataSource.new_for_type(type, entry_name, conf, @context, @logger) end |