Class: Contentful::Importer::Command
- Inherits:
-
CLAide::Command
- Object
- CLAide::Command
- Contentful::Importer::Command
- Defined in:
- lib/contentful/importer/command.rb
Direct Known Subclasses
Import, ImportAssets, ImportEntries, ImportModel, Publish, PublishAssets, PublishEntries, TestCredentials
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#converter ⇒ Object
readonly
Returns the value of attribute converter.
-
#importer ⇒ Object
readonly
Returns the value of attribute importer.
-
#json_validator ⇒ Object
readonly
Returns the value of attribute json_validator.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(args) ⇒ Command
constructor
A new instance of Command.
- #run ⇒ Object
Constructor Details
#initialize(args) ⇒ Command
Returns a new instance of Command.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/contentful/importer/command.rb', line 59 def initialize(args) super(args) @settings = {} settings_file = args.option('configuration') @settings.merge!(YAML.load_file(settings_file)) if settings_file # CLI options can override settings of the same name self.class..map { |opt| opt.first.split('=').first.split('-').last }.each do |opt| arg = args.option(opt) arg &&= arg.to_i if opt == 'threads' @settings[opt] = arg if arg end @settings = @settings.with_indifferent_access @settings[:threads] = 1 if @settings[:threads].nil? end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
32 33 34 |
# File 'lib/contentful/importer/command.rb', line 32 def config @config end |
#converter ⇒ Object (readonly)
Returns the value of attribute converter.
32 33 34 |
# File 'lib/contentful/importer/command.rb', line 32 def converter @converter end |
#importer ⇒ Object (readonly)
Returns the value of attribute importer.
32 33 34 |
# File 'lib/contentful/importer/command.rb', line 32 def importer @importer end |
#json_validator ⇒ Object (readonly)
Returns the value of attribute json_validator.
32 33 34 |
# File 'lib/contentful/importer/command.rb', line 32 def json_validator @json_validator end |
Class Method Details
.data_options ⇒ Object
44 45 46 |
# File 'lib/contentful/importer/command.rb', line 44 def self. [['--data_dir=data', 'The directory to use for input, temporary data and logs.']] end |
.options ⇒ Object
39 40 41 42 |
# File 'lib/contentful/importer/command.rb', line 39 def self. [['--configuration=config.yaml', 'Use the given configuration file.'], ['--access_token=XXX', 'The CMA access token to be used.']].concat(super).sort end |
.space_options ⇒ Object
48 49 50 51 52 53 |
# File 'lib/contentful/importer/command.rb', line 48 def self. [['--organization_id=YYY', 'Select organization if you are member of more than one.'], ['--space_id=ZZZ', 'Import into an existing space.'], ['--space_name=ZZZ', 'Import into a new space with the given name.'], ['--default_locale=de-DE', 'Locale to use if a new space is being created.']] end |
.thread_options ⇒ Object
55 56 57 |
# File 'lib/contentful/importer/command.rb', line 55 def self. [['--threads=1', 'Number of threads to be used, can be either 1 or 2.']] end |
Instance Method Details
#run ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/contentful/importer/command.rb', line 78 def run @config = Configuration.new(@settings) @importer = ParallelImporter.new(@config) @converter = ContentfulModelToJson.new(@config) @json_validator = JsonSchemaValidator.new(@config) json_validator.validate_schemas end |