class TapClutch::Runner

Kicks off tap-clutch process

Attributes

config_filename[R]
state_filename[R]
stream[R]
verbose[R]

Public Class Methods

new(argv, stream: $stderr, config: nil, state: nil) click to toggle source
# File lib/runner.rb, line 19
def initialize(argv, stream: $stderr, config: nil, state: nil)
  @stream = stream
  @config = config
  @state = state
  parser.parse! argv
end

Public Instance Methods

config() click to toggle source
# File lib/runner.rb, line 32
def config
  @config ||= read_json(config_filename)
end
perform() click to toggle source
# File lib/runner.rb, line 26
def perform
  return stream.puts(parser) if config.keys.empty?
  output_schemata
  client.process state['start_date']
end
state() click to toggle source
# File lib/runner.rb, line 36
def state
  @state ||= read_json(state_filename)
end

Private Instance Methods

client() click to toggle source

rubocop: disable Metrics/AbcSize

# File lib/runner.rb, line 49
def client
  @client ||= TapClutch::Client.new(
    api_key: config['api_key'],
    api_secret: config['api_secret'],
    api_base: config['api_base'],
    brand: config['brand'],
    location: config['location'],
    terminal: config['terminal'],
    username: config['username'],
    password: config['password'],
    verbose: verbose,
    state: Concurrent::Hash.new.merge!(state),
    stream: stream
  )
end
output_schemata() click to toggle source
# File lib/runner.rb, line 42
def output_schemata
  TapClutch::Models::Base.subclasses.each do |model|
    client.output model.schema
  end
end
parser() click to toggle source
# File lib/runner.rb, line 71
def parser
  @parser ||= OptionParser.new do |opts|
    opts.banner = "Usage: #{$PROGRAM_NAME} [options]"
    opts.on('-c', '--config filename', 'Set config file (json)') do |config|
      @config_filename = config
    end

    opts.on('-s', '--state filename', 'Set state file (json)') do |state|
      @state_filename = state
    end

    opts.on('-v', '--verbose', 'Enables verbose logging to STDERR') do
      @verbose = true
    end
  end
end
read_json(filename) click to toggle source

rubocop: enable Metrics/AbcSize

# File lib/runner.rb, line 66
def read_json(filename)
  return JSON.parse(File.read(filename)) if filename
  {}
end