Class: Automation::API::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/automation/api/cli.rb

Overview

Automation::API::CLI

Constant Summary collapse

DEFAULT_PROFILE =
'starter'
PROFILE_PATH =
"#{File.expand_path('../../../', __dir__)}/config"
PROFILE_EXAMPLE =
"#{PROFILE_PATH}/profile.yml.example"
ARCHETYPES =
%w[
  complex
  coffee_shop
  empty
].freeze
PROCESSORS =
%w[
  tgate_dev
  tgate_prod
  tgate_mock
  clover
  freedompay_uat
  tgate_emulator_uat
  broken
  none
].freeze

Instance Method Summary collapse

Instance Method Details

#create(profile = DEFAULT_PROFILE) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/automation/api/cli.rb', line 85

def create(profile = DEFAULT_PROFILE)
  @saved  = {}
  @client = Automation::API::Client.create(options)

  file_path = File.expand_path("#{profile}.yml", options[:profile_path])

  raise 'Store profile not found' unless File.exist?(file_path)

  configuration = YAML.load_file(file_path)

  configuration.each do |key, value|
    next unless private_methods.include?(key)

    send(key, value)
  end
end

#listObject



109
110
111
112
113
114
115
116
117
118
# File 'lib/automation/api/cli.rb', line 109

def list
  regex      = %r{([^\/]*).yml$}x
  file_paths = Dir["#{options[:profile_path]}/*"]

  file_paths.map { |file| file.match(regex) }
            .compact
            .map { |match| match[1] }
            .sort
            .each { |profile| puts profile }
end

#new_profile(name = 'custom_profile') ⇒ Object



144
145
146
147
148
# File 'lib/automation/api/cli.rb', line 144

def new_profile(name = 'custom_profile')
  dest = File.expand_path("#{name}.yml", options[:profile_path])

  FileUtils.cp(PROFILE_EXAMPLE, dest)
end

#view(store_type = DEFAULT_STORE_TYPE) ⇒ Object



127
128
129
130
131
132
133
134
135
# File 'lib/automation/api/cli.rb', line 127

def view(store_type = DEFAULT_STORE_TYPE)
  path = "#{options[:config_path]}/#{store_type}.yml"

  if File.exist?(path)
    puts File.read(path)
  else
    puts 'No configuration file found'
  end
end