Class: Contentful::Configuration
- Inherits:
-
Object
- Object
- Contentful::Configuration
- Defined in:
- lib/configuration.rb
Instance Attribute Summary collapse
-
#assets_dir ⇒ Object
readonly
Returns the value of attribute assets_dir.
-
#collections_dir ⇒ Object
readonly
Returns the value of attribute collections_dir.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#data_dir ⇒ Object
readonly
Returns the value of attribute data_dir.
-
#db ⇒ Object
readonly
Returns the value of attribute db.
-
#drupal_base_url ⇒ Object
readonly
Returns the value of attribute drupal_base_url.
-
#drupal_content_types ⇒ Object
readonly
Returns the value of attribute drupal_content_types.
-
#entries_dir ⇒ Object
readonly
Returns the value of attribute entries_dir.
-
#space_id ⇒ Object
readonly
Returns the value of attribute space_id.
Instance Method Summary collapse
- #adapter_setup ⇒ Object
- #define_adapter ⇒ Object
-
#initialize(settings) ⇒ Configuration
constructor
A new instance of Configuration.
- #validate_required_parameters ⇒ Object
Constructor Details
#initialize(settings) ⇒ Configuration
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/configuration.rb', line 16 def initialize(settings) @config = settings validate_required_parameters @data_dir = config['data_dir'] @collections_dir = "#{data_dir}/collections" @entries_dir = "#{data_dir}/entries" @assets_dir = "#{data_dir}/assets" @space_id = config['space_id'] @drupal_content_types = JSON.parse(File.read(config['drupal_content_types_json']), symbolize_names: true).with_indifferent_access @drupal_base_url = config['drupal_base_url'] @db = adapter_setup end |
Instance Attribute Details
#assets_dir ⇒ Object (readonly)
Returns the value of attribute assets_dir.
6 7 8 |
# File 'lib/configuration.rb', line 6 def assets_dir @assets_dir end |
#collections_dir ⇒ Object (readonly)
Returns the value of attribute collections_dir.
6 7 8 |
# File 'lib/configuration.rb', line 6 def collections_dir @collections_dir end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
6 7 8 |
# File 'lib/configuration.rb', line 6 def config @config end |
#data_dir ⇒ Object (readonly)
Returns the value of attribute data_dir.
6 7 8 |
# File 'lib/configuration.rb', line 6 def data_dir @data_dir end |
#db ⇒ Object (readonly)
Returns the value of attribute db.
6 7 8 |
# File 'lib/configuration.rb', line 6 def db @db end |
#drupal_base_url ⇒ Object (readonly)
Returns the value of attribute drupal_base_url.
6 7 8 |
# File 'lib/configuration.rb', line 6 def drupal_base_url @drupal_base_url end |
#drupal_content_types ⇒ Object (readonly)
Returns the value of attribute drupal_content_types.
6 7 8 |
# File 'lib/configuration.rb', line 6 def drupal_content_types @drupal_content_types end |
#entries_dir ⇒ Object (readonly)
Returns the value of attribute entries_dir.
6 7 8 |
# File 'lib/configuration.rb', line 6 def entries_dir @entries_dir end |
#space_id ⇒ Object (readonly)
Returns the value of attribute space_id.
6 7 8 |
# File 'lib/configuration.rb', line 6 def space_id @space_id end |
Instance Method Details
#adapter_setup ⇒ Object
41 42 43 |
# File 'lib/configuration.rb', line 41 def adapter_setup Sequel.connect(:adapter => config['adapter'], :user => config['user'], :host => config['host'], :database => config['database'], :password => config['password']) end |
#define_adapter ⇒ Object
35 36 37 38 39 |
# File 'lib/configuration.rb', line 35 def define_adapter %w(adapter user host database).each do |param| fail ArgumentError, "Set database connection parameters [adapter, host, database, user, password]. Missing the '#{param}' parameter! Password is optional. Check README!" unless config[param] end end |
#validate_required_parameters ⇒ Object
29 30 31 32 33 |
# File 'lib/configuration.rb', line 29 def validate_required_parameters fail ArgumentError, 'Set PATH to data_dir, the destination for all generated files. Check README' if config['data_dir'].nil? fail ArgumentError, 'Set PATH to drupal_content_types_json. File with Drupal database structure. View README' if config['drupal_content_types_json'].nil? define_adapter end |