Module: DbAgile::Command::Bulk::Commons
Instance Attribute Summary collapse
-
#allbut ⇒ Object
Columns to allbut.
-
#conn_options ⇒ Object
Connection options.
-
#dataset ⇒ Object
Dataset whose contents must be shown.
-
#format ⇒ Object
Output/input format [ruby, csv, json].
-
#io_options ⇒ Object
Input/output options.
-
#select ⇒ Object
Columns to select.
-
#type_system ⇒ Object
Type system to use.
Instance Method Summary collapse
-
#add_csv_options(opt) ⇒ Object
(also: #add_csv_input_options, #add_csv_output_options)
Adds the CSV options.
-
#add_html_output_options(opt) ⇒ Object
Adds output HTML options.
-
#add_input_format_options(opt) ⇒ Object
Adds the format options for input.
-
#add_json_output_options(opt) ⇒ Object
Adds output JSON options.
-
#add_output_format_options(opt) ⇒ Object
Adds the format options for output.
-
#add_select_options(opt) ⇒ Object
Adds the select/allbut options.
-
#add_text_output_options(opt) ⇒ Object
Adds output TEXT options.
- #add_typesafe_options(opt) ⇒ Object
-
#set_default_options ⇒ Object
Builds default io options.
Instance Attribute Details
#allbut ⇒ Object
Columns to allbut
25 26 27 |
# File 'lib/dbagile/command/bulk/commons.rb', line 25 def allbut @allbut end |
#conn_options ⇒ Object
Connection options
10 11 12 |
# File 'lib/dbagile/command/bulk/commons.rb', line 10 def @conn_options end |
#dataset ⇒ Object
Dataset whose contents must be shown
19 20 21 |
# File 'lib/dbagile/command/bulk/commons.rb', line 19 def dataset @dataset end |
#format ⇒ Object
Output/input format [ruby, csv, json]
7 8 9 |
# File 'lib/dbagile/command/bulk/commons.rb', line 7 def format @format end |
#io_options ⇒ Object
Input/output options
13 14 15 |
# File 'lib/dbagile/command/bulk/commons.rb', line 13 def @io_options end |
#select ⇒ Object
Columns to select
22 23 24 |
# File 'lib/dbagile/command/bulk/commons.rb', line 22 def select @select end |
#type_system ⇒ Object
Type system to use
16 17 18 |
# File 'lib/dbagile/command/bulk/commons.rb', line 16 def type_system @type_system end |
Instance Method Details
#add_csv_options(opt) ⇒ Object Also known as: add_csv_input_options, add_csv_output_options
Adds the CSV options
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/dbagile/command/bulk/commons.rb', line 88 def (opt) opt.on("--headers", "-h", "Read/Write column names on first line") do [:csv][:headers] = true end opt.on("--separator=C", "Use C as column separator character") do |value| [:csv][:col_sep] = value end opt.on("--quote=C", "Use C as quoting character") do |value| [:csv][:quote_char] = value end opt.on("--force-quotes", "Force quoting?") do [:csv][:force_quotes] = true end opt.on("--skip-blanks", "Skip blank lines?") do [:csv][:skip_blanks] = true end end |
#add_html_output_options(opt) ⇒ Object
Adds output HTML options
129 130 |
# File 'lib/dbagile/command/bulk/commons.rb', line 129 def (opt) end |
#add_input_format_options(opt) ⇒ Object
Adds the format options for input
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/dbagile/command/bulk/commons.rb', line 76 def (opt) opt.on('--format=X', [:csv, :json, :yaml, :ruby], "Import dataset from (csv, json, yaml, ruby)") do |value| self.format = value end opt.on("--csv", "Import dataset from csv (default)"){ self.format = :csv } opt.on("--json", "Import dataset from json"){ self.format = :json } opt.on("--ruby", "Import dataset from ruby code"){ self.format = :ruby } opt.on("--yaml", "Import dataset from yaml"){ self.format = :yaml } end |
#add_json_output_options(opt) ⇒ Object
Adds output JSON options
109 110 111 112 113 |
# File 'lib/dbagile/command/bulk/commons.rb', line 109 def (opt) opt.on("--[no-]pretty", "Generate a pretty JSON document") do |value| [:json][:pretty] = value end end |
#add_output_format_options(opt) ⇒ Object
Adds the format options for output
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/dbagile/command/bulk/commons.rb', line 61 def (opt) opt.on('--format=X', [:csv, :text, :json, :yaml, :ruby, :xml, :html], "Export dataset in (csv, text, json, yaml, ruby, xml, html)") do |value| self.format = value end opt.on("--csv", "Export dataset in csv (default)"){ self.format = :csv } opt.on("--text", "Export dataset as a plain text table"){ self.format = :text } opt.on("--json", "Export dataset in json"){ self.format = :json } opt.on("--yaml", "Export dataset in yaml"){ self.format = :yaml } opt.on("--xml", "Export dataset in xml"){ self.format = :xml } opt.on("--html", "Export dataset in html"){ self.format = :html } opt.on("--ruby", "Export dataset as ruby code"){ self.format = :ruby } end |
#add_select_options(opt) ⇒ Object
Adds the select/allbut options
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/dbagile/command/bulk/commons.rb', line 36 def (opt) opt.on('--select x,y,z', Array, "Select x, y, z columns only") do |value| self.select = value.collect{|c| c.to_sym} end opt.on('--allbut x,y,z', Array, "Select all but x, y, z columns") do |value| self.allbut = value.collect{|c| c.to_sym} end end |
#add_text_output_options(opt) ⇒ Object
Adds output TEXT options
116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/dbagile/command/bulk/commons.rb', line 116 def (opt) opt.on("--wrap-at=X", Integer, "Wraps table after X's character (no wrap by default)") do |x| [:text][:wrap_at] = x end opt.on("--truncate-at=X", Integer, "Truncate row lines at X character") do |x| [:text][:truncate_at] = x [:text][:append_with] = '...' end end |
#add_typesafe_options(opt) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/dbagile/command/bulk/commons.rb', line 47 def (opt) opt.on("--type-safe=[X]", [:ruby], "Read/Write type-safe values for (ruby)") do |value| case value when :ruby, NilClass require 'sbyc/type_system/ruby' self.type_system = SByC::TypeSystem::Ruby else raise ArgumentError, "Unknown type system #{value}" end end end |
#set_default_options ⇒ Object
Builds default io options
28 29 30 31 32 33 |
# File 'lib/dbagile/command/bulk/commons.rb', line 28 def self.format = :csv self.type_system = nil self. = {} self. = Hash.new{|h,k| h[k] = {}} end |