Class: Mycmd::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/mycmd/client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClient

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

#resultObject (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

#commandObject



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


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