Class: ShopifyTransporter::Generate

Inherits:
BaseGroup
  • Object
show all
Defined in:
lib/shopify_transporter/generators/generate.rb

Constant Summary

Constants inherited from BaseGroup

BaseGroup::SUPPORTED_PLATFORMS_MAPPING

Instance Method Summary collapse

Methods inherited from BaseGroup

#config_filename, #name_components, source_root

Instance Method Details

#add_stage_to_configObject



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/shopify_transporter/generators/generate.rb', line 42

def add_stage_to_config
  config_file = YAML.load_file(config_filename)
  unless class_included_in?(config_file)
    pipeline_class_hash = { @pipeline_class.to_s => nil, 'type' => 'custom' }
    config_file['object_types'][@object_type.downcase]['pipeline_stages'] << pipeline_class_hash
    File.open(config_filename, 'w') { |f| f.write config_file.to_yaml }
    say('Updated config.yml with the new pipeline stage', :green)
    return
  end

  say("Warning: The pipeline stage #{@pipeline_class} already exists in the config.yml", :blue)
end

#generate_stageObject



35
36
37
38
39
40
# File 'lib/shopify_transporter/generators/generate.rb', line 35

def generate_stage
  template(
    'templates/custom_stage.tt',
    "lib/custom_pipeline_stages/#{pipeline_snake_name}.rb"
  )
end

#object_typeObject



10
11
12
# File 'lib/shopify_transporter/generators/generate.rb', line 10

def object_type
  @object_type ||= options[:object].capitalize
end

#pipeline_classObject



25
26
27
# File 'lib/shopify_transporter/generators/generate.rb', line 25

def pipeline_class
  @pipeline_class ||= @name_components.map(&:classify).join('')
end

#pipeline_snake_nameObject



21
22
23
# File 'lib/shopify_transporter/generators/generate.rb', line 21

def pipeline_snake_name
  name_components.map(&:underscore).join('_')
end

#platformObject



29
30
31
32
33
# File 'lib/shopify_transporter/generators/generate.rb', line 29

def platform
  platform_type = YAML.load_file(config_filename)['platform_type']
  @platform_file_path ||= SUPPORTED_PLATFORMS_MAPPING[platform_type]
  @platform ||= platform_type.underscore
end

#validate_config_existsObject



14
15
16
17
18
19
# File 'lib/shopify_transporter/generators/generate.rb', line 14

def validate_config_exists
  unless File.exist?(config_filename)
    say('Cannot find config.yml at project root', :red)
    exit 1
  end
end