Class: Myq::Commands
- Inherits:
-
Thor
- Object
- Thor
- Myq::Commands
- Defined in:
- lib/myq/commands.rb
Instance Method Summary collapse
-
#initialize(args = [], options = {}, config = {}) ⇒ Commands
constructor
A new instance of Commands.
- #query_file(file) ⇒ Object
- #query_inline(query) ⇒ Object
- #sample(table) ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(args = [], options = {}, config = {}) ⇒ Commands
Returns a new instance of Commands.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/myq/commands.rb', line 21 def initialize(args = [], = {}, config = {}) super(args, , config) = config[:shell].base. if File.exist?("#{ENV['HOME']}/.database.yml") data = YAML.load_file("#{ENV['HOME']}/.database.yml")[['profile']] host = data['host'] username = data['username'] password = data['password'] database = data['database'] port = data['port'] else host = ['host'] username = ['username'] password = ['password'] database = ['database'] port = ['port'] end @client = Mysql2::Client.new(host: host, username: username, password: password, database: database, port: port) end |
Instance Method Details
#query_file(file) ⇒ Object
47 48 49 |
# File 'lib/myq/commands.rb', line 47 def query_file(file) query(File.read(file)) end |
#query_inline(query) ⇒ Object
42 43 44 |
# File 'lib/myq/commands.rb', line 42 def query_inline(query) query(query) end |
#sample(table) ⇒ Object
53 54 55 |
# File 'lib/myq/commands.rb', line 53 def sample(table) query("select * from #{table} limit #{['limit']}") end |
#version ⇒ Object
58 59 60 |
# File 'lib/myq/commands.rb', line 58 def version puts VERSION end |