Class: Podrb::Commands::Podcasts::Runner

Inherits:
BaseRunner
  • Object
show all
Defined in:
lib/podrb/commands/podcasts/runner.rb

Instance Method Summary collapse

Methods inherited from BaseRunner

call

Instance Method Details

#call(options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/podrb/commands/podcasts/runner.rb', line 10

def call(options = {})
  parsed_options = parse_options(options)
  columns = parsed_options["fields"] || ALL_COLUMNS
  db = Infrastructure::Storage::SQL.new(db: podrb_db_dir)
  records = db.query("select #{columns.join(", ")} from podcasts")
  build_success_response(
    details: records.empty? ? :empty_table : :records_found,
    metadata: {records: records, columns: columns}
  )
rescue Infrastructure::Storage::Exceptions::WrongSyntax => exc
  cause = exc.message
  if cause.include?("no such column")
    invalid_column = cause.delete_prefix("no such column: ")
    build_failure_response(
      details: :invalid_column,
      metadata: {invalid_column: invalid_column}
    )
  end
end