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.
-
#content_types ⇒ Object
readonly
Returns the value of attribute content_types.
-
#contentful_structure ⇒ Object
readonly
Returns the value of attribute contentful_structure.
-
#converted_model_dir ⇒ Object
readonly
Returns the value of attribute converted_model_dir.
-
#data_dir ⇒ Object
readonly
Returns the value of attribute data_dir.
-
#db ⇒ Object
readonly
Returns the value of attribute db.
-
#entries_dir ⇒ Object
readonly
Returns the value of attribute entries_dir.
-
#helpers_dir ⇒ Object
readonly
Returns the value of attribute helpers_dir.
Instance Method Summary collapse
- #adapter_setup ⇒ Object
- #create_empty_contentful_structure_file ⇒ Object
- #define_adapter ⇒ Object
- #file_exists? ⇒ Boolean
-
#initialize(settings) ⇒ Configuration
constructor
A new instance of Configuration.
-
#load_contentful_structure_file ⇒ Object
If contentful_structure JSON file exists, it will load the file.
- #load_existing_contentful_structure_file ⇒ Object
- #validate_required_parameters ⇒ Object
Constructor Details
#initialize(settings) ⇒ Configuration
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/configuration.rb', line 17 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" @helpers_dir = "#{data_dir}/helpers" @contentful_structure = load_contentful_structure_file @db = adapter_setup @converted_model_dir = @config['converted_model_dir'] @content_types = config['content_model_json'] 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 |
#content_types ⇒ Object (readonly)
Returns the value of attribute content_types.
6 7 8 |
# File 'lib/configuration.rb', line 6 def content_types @content_types end |
#contentful_structure ⇒ Object (readonly)
Returns the value of attribute contentful_structure.
6 7 8 |
# File 'lib/configuration.rb', line 6 def contentful_structure @contentful_structure end |
#converted_model_dir ⇒ Object (readonly)
Returns the value of attribute converted_model_dir.
6 7 8 |
# File 'lib/configuration.rb', line 6 def converted_model_dir @converted_model_dir 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 |
#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 |
#helpers_dir ⇒ Object (readonly)
Returns the value of attribute helpers_dir.
6 7 8 |
# File 'lib/configuration.rb', line 6 def helpers_dir @helpers_dir end |
Instance Method Details
#adapter_setup ⇒ Object
65 66 67 |
# File 'lib/configuration.rb', line 65 def adapter_setup Sequel.connect(:adapter => config['adapter'], :user => config['user'], :host => config['host'], :database => config['database'], :password => config['password']) end |
#create_empty_contentful_structure_file ⇒ Object
56 57 58 59 |
# File 'lib/configuration.rb', line 56 def create_empty_contentful_structure_file File.open(@config['contentful_structure_dir'], 'w') { |file| file.write({}) } load_existing_contentful_structure_file end |
#define_adapter ⇒ Object
40 41 42 43 44 |
# File 'lib/configuration.rb', line 40 def define_adapter %w(adapter host database).each do |param| fail ArgumentError, "Set database connection parameters [adapter, host, database, user, password]. Missing the '#{param}' parameter! Password and User are optional. View README!" unless config[param] end end |
#file_exists? ⇒ Boolean
52 53 54 |
# File 'lib/configuration.rb', line 52 def file_exists? File.exists?(config['contentful_structure_dir']) end |
#load_contentful_structure_file ⇒ Object
If contentful_structure JSON file exists, it will load the file. If not, it will automatically create an empty file. This file is required to convert contentful model to contentful import structure.
48 49 50 |
# File 'lib/configuration.rb', line 48 def load_contentful_structure_file file_exists? ? load_existing_contentful_structure_file : create_empty_contentful_structure_file end |
#load_existing_contentful_structure_file ⇒ Object
61 62 63 |
# File 'lib/configuration.rb', line 61 def load_existing_contentful_structure_file JSON.parse(File.read(config['contentful_structure_dir']), symbolize_names: true).with_indifferent_access end |
#validate_required_parameters ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/configuration.rb', line 31 def validate_required_parameters fail ArgumentError, 'Set PATH to data_dir. Folder where all data will be stored. View README' if config['data_dir'].nil? fail ArgumentError, 'Set PATH to contentful structure JSON file. View README' if config['contentful_structure_dir'].nil? fail ArgumentError, 'Set PATH to mapping structure JSON file. View README' if config['mapping_dir'].nil? fail ArgumentError, 'Set PATH to Content model JSON file, which is downloaded structure from Contentful. View README' if config['converted_model_dir'].nil? fail ArgumentError, 'Set PATH to converted contentful model and saved as JSON file. View README' if config['content_model_json'].nil? define_adapter end |