class DataPitcher::Command

Public Class Methods

new(spreadsheet_key:, worksheet_title: nil, sql_path:, dry_run: true, index: 1) click to toggle source
# File lib/data_pitcher/command.rb, line 3
def initialize(spreadsheet_key:, worksheet_title: nil, sql_path:, dry_run: true, index: 1)
  @spreadsheet_key = spreadsheet_key
  @worksheet_title = worksheet_title
  @sql_path = sql_path
  @dry_run = dry_run
  @index = index
end

Public Instance Methods

dry_run() click to toggle source
# File lib/data_pitcher/command.rb, line 15
def dry_run
  puts dry_run_log
  false
end
dry_run_log() click to toggle source
# File lib/data_pitcher/command.rb, line 45
    def dry_run_log
      <<-EOS
##{@index} command
  spreadsheet_key: #{@spreadsheet_key}
  worksheet_title: #{@worksheet_title || '(first worksheet)'}
    valid?: #{spreadsheet.valid?}
  sql_path: #{@sql_path}
    valid?: #{executor.valid?}
      EOS
    end
execute() click to toggle source
# File lib/data_pitcher/command.rb, line 11
def execute
  @dry_run ? dry_run : run
end
executor() click to toggle source
# File lib/data_pitcher/command.rb, line 37
def executor
  @executor ||= DataPitcher::Executor.new(sql_query)
end
run() click to toggle source
# File lib/data_pitcher/command.rb, line 20
def run
  unless spreadsheet.valid?
    puts "[ERROR] ##{@index} command skipped: DataPitcher can not access to spreadsheet (#{@spreadsheet_key})"
    return false
  end
  unless executor.valid?
    puts "[ERROR] ##{@index} command skipped: SQL is invalid (#{@sql_path})"
    return false
  end
  spreadsheet.replace_worksheet_with_query(sql_query)
  true
end
spreadsheet() click to toggle source
# File lib/data_pitcher/command.rb, line 33
def spreadsheet
  @spreadsheet ||= DataPitcher::Spreadsheet.new(@spreadsheet_key, @worksheet_title)
end
sql_query() click to toggle source
# File lib/data_pitcher/command.rb, line 41
def sql_query
  @sql_query ||= File.read(@sql_path)
end