Class: Jekyll::Contentful::DataExporter
- Inherits:
-
Object
- Object
- Jekyll::Contentful::DataExporter
- Defined in:
- lib/jekyll-contentful-data-import/data_exporter.rb
Constant Summary collapse
- DATA_FOLDER =
'_data'- CONTENTFUL_FOLDER =
'contentful'- SPACES_FOLDER =
'spaces'
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #base_directory ⇒ Object
- #destination_directory ⇒ Object
- #destination_file ⇒ Object
-
#initialize(name, entries, config = {}) ⇒ DataExporter
constructor
A new instance of DataExporter.
- #run ⇒ Object
- #setup_directory ⇒ Object
Constructor Details
#initialize(name, entries, config = {}) ⇒ DataExporter
Returns a new instance of DataExporter.
12 13 14 15 16 |
# File 'lib/jekyll-contentful-data-import/data_exporter.rb', line 12 def initialize(name, entries, config = {}) @name = name @entries = entries @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
10 11 12 |
# File 'lib/jekyll-contentful-data-import/data_exporter.rb', line 10 def config @config end |
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
10 11 12 |
# File 'lib/jekyll-contentful-data-import/data_exporter.rb', line 10 def entries @entries end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
10 11 12 |
# File 'lib/jekyll-contentful-data-import/data_exporter.rb', line 10 def name @name end |
Instance Method Details
#base_directory ⇒ Object
26 27 28 29 30 31 |
# File 'lib/jekyll-contentful-data-import/data_exporter.rb', line 26 def base_directory directory = File.(Dir.pwd) directory = File.join(directory, config['base_path']) if config.key?('base_path') directory end |
#destination_directory ⇒ Object
33 34 35 |
# File 'lib/jekyll-contentful-data-import/data_exporter.rb', line 33 def destination_directory File.join(base_directory, DATA_FOLDER, CONTENTFUL_FOLDER, SPACES_FOLDER) end |
#destination_file ⇒ Object
37 38 39 |
# File 'lib/jekyll-contentful-data-import/data_exporter.rb', line 37 def destination_file File.join(destination_directory, "#{name}.yaml") end |
#run ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/jekyll-contentful-data-import/data_exporter.rb', line 18 def run setup_directory File.open(destination_file, 'w') do |file| file.write(::Jekyll::Contentful::Serializer.new(entries, config).to_yaml) end end |
#setup_directory ⇒ Object
41 42 43 |
# File 'lib/jekyll-contentful-data-import/data_exporter.rb', line 41 def setup_directory FileUtils.mkdir_p destination_directory end |