Class: Jekyll::Contentful::DataExporter
- Inherits:
-
Object
- Object
- Jekyll::Contentful::DataExporter
- Defined in:
- lib/jekyll-contentful-data-import/data_exporter.rb
Overview
Data Exporter Class
Serializes Contentful data into YAML files
Constant Summary collapse
- DATA_FOLDER =
'_data'.freeze
- CONTENTFUL_FOLDER =
'contentful'.freeze
- SPACES_FOLDER =
'spaces'.freeze
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.
15 16 17 18 19 |
# File 'lib/jekyll-contentful-data-import/data_exporter.rb', line 15 def initialize(name, entries, config = {}) @name = name @entries = entries @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
13 14 15 |
# File 'lib/jekyll-contentful-data-import/data_exporter.rb', line 13 def config @config end |
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
13 14 15 |
# File 'lib/jekyll-contentful-data-import/data_exporter.rb', line 13 def entries @entries end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
13 14 15 |
# File 'lib/jekyll-contentful-data-import/data_exporter.rb', line 13 def name @name end |
Instance Method Details
#base_directory ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/jekyll-contentful-data-import/data_exporter.rb', line 34 def base_directory directory = File.(Dir.pwd) if config.key?('base_path') directory = File.join( directory, config['base_path'] ) end directory end |
#destination_directory ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/jekyll-contentful-data-import/data_exporter.rb', line 46 def destination_directory destination_dir = File.join( base_directory, DATA_FOLDER, CONTENTFUL_FOLDER, SPACES_FOLDER ) if config.key?('destination') destination_dir = File.join( base_directory, DATA_FOLDER, config['destination'] ) end destination_dir end |
#destination_file ⇒ Object
60 61 62 |
# File 'lib/jekyll-contentful-data-import/data_exporter.rb', line 60 def destination_file File.join(destination_directory, "#{name}.yaml") end |
#run ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/jekyll-contentful-data-import/data_exporter.rb', line 21 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
64 65 66 |
# File 'lib/jekyll-contentful-data-import/data_exporter.rb', line 64 def setup_directory FileUtils.mkdir_p destination_directory end |