Class: DataPitcher::Command
- Inherits:
-
Object
- Object
- DataPitcher::Command
- Defined in:
- lib/data_pitcher/command.rb
Instance Method Summary collapse
- #dry_run ⇒ Object
- #dry_run_log ⇒ Object
- #execute ⇒ Object
- #executor ⇒ Object
-
#initialize(spreadsheet_key, sql_path, dry_run: true, index: 1) ⇒ Command
constructor
A new instance of Command.
- #run ⇒ Object
- #spreadsheet ⇒ Object
- #sql_query ⇒ Object
Constructor Details
#initialize(spreadsheet_key, sql_path, dry_run: true, index: 1) ⇒ Command
Returns a new instance of Command.
3 4 5 6 7 8 |
# File 'lib/data_pitcher/command.rb', line 3 def initialize(spreadsheet_key, sql_path, dry_run: true, index: 1) @spreadsheet_key = spreadsheet_key @sql_path = sql_path @dry_run = dry_run @index = index end |
Instance Method Details
#dry_run ⇒ Object
14 15 16 17 |
# File 'lib/data_pitcher/command.rb', line 14 def dry_run puts dry_run_log false end |
#dry_run_log ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/data_pitcher/command.rb', line 44 def dry_run_log <<-EOS ##{@index} command spreadsheet_key: #{@spreadsheet_key} valid?: #{spreadsheet.valid?} sql_path: #{@sql_path} valid?: #{executor.valid?} EOS end |
#execute ⇒ Object
10 11 12 |
# File 'lib/data_pitcher/command.rb', line 10 def execute @dry_run ? dry_run : run end |
#executor ⇒ Object
36 37 38 |
# File 'lib/data_pitcher/command.rb', line 36 def executor @executor ||= DataPitcher::Executor.new(sql_query) end |
#run ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/data_pitcher/command.rb', line 19 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 ⇒ Object
32 33 34 |
# File 'lib/data_pitcher/command.rb', line 32 def spreadsheet @spreadsheet ||= DataPitcher::Spreadsheet.new(@spreadsheet_key) end |
#sql_query ⇒ Object
40 41 42 |
# File 'lib/data_pitcher/command.rb', line 40 def sql_query @sql_query ||= File.read(@sql_path) end |