Class: Jsonsql::Command
- Inherits:
-
CLAide::Command
- Object
- CLAide::Command
- Jsonsql::Command
- Defined in:
- lib/jsonsql/command.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(argv) ⇒ Command
constructor
A new instance of Command.
- #run ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(argv) ⇒ Command
Returns a new instance of Command.
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/jsonsql/command.rb', line 19 def initialize(argv) @jsons = [] while argument = argv.shift_argument @jsons << argument end @verbose = argv.flag?('verbose', false) @console = argv.flag?('console', true) @filename = argv.option('save-to') || ':memory:' @table_name = argv.option('table-name') || 'table' super end |
Class Method Details
.options ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/jsonsql/command.rb', line 11 def self. [ ['--console', 'After all commands are run, open pry console with this data'], ['--save-to=[filename]', 'If set, sqlite3 db is left on disk at this path'], ['--table-name=[table]', 'Override the default table name (table)'] ].concat(super) end |
Instance Method Details
#run ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/jsonsql/command.rb', line 40 def run sequel = Sequel.sqlite(@filename) importer = Importer.new(database: sequel, table_name: @table_name, verbose: @verbose) importer.import @jsons if @console importer.database.pry end end |
#validate! ⇒ Object
33 34 35 36 37 38 |
# File 'lib/jsonsql/command.rb', line 33 def validate! super if @jsons.size == 0 help! "At least one JSON files is required." end end |