Class: Arguments
- Inherits:
-
Object
- Object
- Arguments
- Defined in:
- lib/sqlite2mysql/services/arguments.rb
Instance Attribute Summary collapse
-
#infer_types ⇒ Object
Returns the value of attribute infer_types.
-
#mysql_db ⇒ Object
Returns the value of attribute mysql_db.
-
#mysql_host ⇒ Object
Returns the value of attribute mysql_host.
-
#mysql_port ⇒ Object
Returns the value of attribute mysql_port.
-
#password ⇒ Object
Returns the value of attribute password.
-
#sqlite_db ⇒ Object
Returns the value of attribute sqlite_db.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #help(_) ⇒ Object
- #host(args) ⇒ Object
- #infer(_) ⇒ Object
-
#initialize(args) ⇒ Arguments
constructor
A new instance of Arguments.
- #pass(args) ⇒ Object
- #port(args) ⇒ Object
- #user(args) ⇒ Object
Constructor Details
#initialize(args) ⇒ Arguments
Returns a new instance of Arguments.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/sqlite2mysql/services/arguments.rb', line 5 def initialize(args) help(args) if args.size == 0 set_defaults unmodified_args = args.dup unmodified_args.each do |arg| if arg.start_with?('--') send(arg[2..-1], args) args.delete(arg) end end @sqlite_db = args.first @mysql_db = args[1] || @sqlite_db.gsub(/[^0-9a-z]/i, '') end |
Instance Attribute Details
#infer_types ⇒ Object
Returns the value of attribute infer_types.
2 3 4 |
# File 'lib/sqlite2mysql/services/arguments.rb', line 2 def infer_types @infer_types end |
#mysql_db ⇒ Object
Returns the value of attribute mysql_db.
2 3 4 |
# File 'lib/sqlite2mysql/services/arguments.rb', line 2 def mysql_db @mysql_db end |
#mysql_host ⇒ Object
Returns the value of attribute mysql_host.
2 3 4 |
# File 'lib/sqlite2mysql/services/arguments.rb', line 2 def mysql_host @mysql_host end |
#mysql_port ⇒ Object
Returns the value of attribute mysql_port.
2 3 4 |
# File 'lib/sqlite2mysql/services/arguments.rb', line 2 def mysql_port @mysql_port end |
#password ⇒ Object
Returns the value of attribute password.
2 3 4 |
# File 'lib/sqlite2mysql/services/arguments.rb', line 2 def password @password end |
#sqlite_db ⇒ Object
Returns the value of attribute sqlite_db.
2 3 4 |
# File 'lib/sqlite2mysql/services/arguments.rb', line 2 def sqlite_db @sqlite_db end |
#username ⇒ Object
Returns the value of attribute username.
2 3 4 |
# File 'lib/sqlite2mysql/services/arguments.rb', line 2 def username @username end |
Instance Method Details
#help(_) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/sqlite2mysql/services/arguments.rb', line 41 def help(_) puts <<-HELP Usage: sqlite2mysql sqlite.db [mysql_name] Options: --help Show this message --infer Infer types for columns --user MySQL username (default: root) --host MySQL host (default: localhost) --pass MySQL password --port MySQL port HELP exit 0 end |
#host(args) ⇒ Object
37 38 39 |
# File 'lib/sqlite2mysql/services/arguments.rb', line 37 def host(args) @mysql_host = get_value_for_flag('--host', args) end |
#infer(_) ⇒ Object
21 22 23 |
# File 'lib/sqlite2mysql/services/arguments.rb', line 21 def infer(_) @infer_types = true end |
#pass(args) ⇒ Object
29 30 31 |
# File 'lib/sqlite2mysql/services/arguments.rb', line 29 def pass(args) @password = get_value_for_flag('--pass', args) end |
#port(args) ⇒ Object
33 34 35 |
# File 'lib/sqlite2mysql/services/arguments.rb', line 33 def port(args) @mysql_port = get_value_for_flag('--port', args) end |
#user(args) ⇒ Object
25 26 27 |
# File 'lib/sqlite2mysql/services/arguments.rb', line 25 def user(args) @username = get_value_for_flag('--user', args) end |