Class: Contentful::Importer::Command

Inherits:
CLAide::Command
  • Object
show all
Defined in:
lib/contentful/importer/command.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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.options.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

#configObject (readonly)

Returns the value of attribute config.



32
33
34
# File 'lib/contentful/importer/command.rb', line 32

def config
  @config
end

#converterObject (readonly)

Returns the value of attribute converter.



32
33
34
# File 'lib/contentful/importer/command.rb', line 32

def converter
  @converter
end

#importerObject (readonly)

Returns the value of attribute importer.



32
33
34
# File 'lib/contentful/importer/command.rb', line 32

def importer
  @importer
end

#json_validatorObject (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_optionsObject



44
45
46
# File 'lib/contentful/importer/command.rb', line 44

def self.data_options
  [['--data_dir=data', 'The directory to use for input, temporary data and logs.']]
end

.optionsObject



39
40
41
42
# File 'lib/contentful/importer/command.rb', line 39

def self.options
  [['--configuration=config.yaml', 'Use the given configuration file.'],
   ['--access_token=XXX', 'The CMA access token to be used.']].concat(super).sort
end

.space_optionsObject



48
49
50
51
52
53
# File 'lib/contentful/importer/command.rb', line 48

def self.space_options
  [['--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_optionsObject



55
56
57
# File 'lib/contentful/importer/command.rb', line 55

def self.thread_options
  [['--threads=1', 'Number of threads to be used, can be either 1 or 2.']]
end

Instance Method Details

#runObject



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