Class: Mycmd::Client
- Inherits:
-
Object
- Object
- Mycmd::Client
- Defined in:
- lib/mycmd/client.rb
Instance Attribute Summary collapse
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Class Method Summary collapse
Instance Method Summary collapse
- #command ⇒ Object
- #execute_task(task) ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #print(header = true) ⇒ Object
- #query(sql) ⇒ Object
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
7 8 9 10 |
# File 'lib/mycmd/client.rb', line 7 def initialize @configuration = Configuration.new @connection = @configuration.connect end |
Instance Attribute Details
#result ⇒ Object (readonly)
Returns the value of attribute result.
5 6 7 |
# File 'lib/mycmd/client.rb', line 5 def result @result end |
Class Method Details
.method_missing(action, *args) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/mycmd/client.rb', line 39 def method_missing(action, *args) client = self.new if client.respond_to? action client.send(action, *args) else super end end |
Instance Method Details
#command ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/mycmd/client.rb', line 26 def command @configuration.to_hash.inject(["mysql"]) do |c,(k,v)| case k when :host then c << "-h#{v}" when :port then c << "-P#{v}" when :username then c << "-u#{v}" when :password then c << "-p#{v}" when :database then c << v end end.join(" ") end |
#execute_task(task) ⇒ Object
17 18 19 20 |
# File 'lib/mycmd/client.rb', line 17 def execute_task(task) @result = @connection.query(@configuration.tasks[task.to_s]) self end |
#print(header = true) ⇒ Object
22 23 24 |
# File 'lib/mycmd/client.rb', line 22 def print(header=true) Printer.new(@result, header).print end |
#query(sql) ⇒ Object
12 13 14 15 |
# File 'lib/mycmd/client.rb', line 12 def query(sql) @result = @connection.query(sql) self end |