Class: Converse::MysqlConversation

Inherits:
Conversation show all
Defined in:
lib/converse/comms/mysql/mysql_conversation.rb

Instance Attribute Summary collapse

Attributes inherited from Conversation

#body, #connection, #headers, #host, #path, #port, #request, #response, #subscribers, #uri

Instance Method Summary collapse

Methods inherited from Conversation

#notify_subscribers, #subscribe

Constructor Details

#initialize(uri) ⇒ MysqlConversation

Returns a new instance of MysqlConversation.



11
12
13
14
15
16
17
# File 'lib/converse/comms/mysql/mysql_conversation.rb', line 11

def initialize(uri)
  super(uri)
  parsed = URI.parse(uri)
  @username = parsed.user
  @password = parsed.password
  @database = parsed.path.gsub(/\//, "")
end

Instance Attribute Details

#database=(value) ⇒ Object (writeonly)

Sets the attribute database

Parameters:

  • value

    the value to set the attribute database to.



8
9
10
# File 'lib/converse/comms/mysql/mysql_conversation.rb', line 8

def database=(value)
  @database = value
end

#password=(value) ⇒ Object (writeonly)

Sets the attribute password

Parameters:

  • value

    the value to set the attribute password to.



7
8
9
# File 'lib/converse/comms/mysql/mysql_conversation.rb', line 7

def password=(value)
  @password = value
end

#queryObject

Returns the value of attribute query.



9
10
11
# File 'lib/converse/comms/mysql/mysql_conversation.rb', line 9

def query
  @query
end

#username=(value) ⇒ Object (writeonly)

Sets the attribute username

Parameters:

  • value

    the value to set the attribute username to.



6
7
8
# File 'lib/converse/comms/mysql/mysql_conversation.rb', line 6

def username=(value)
  @username = value
end

Instance Method Details

#askObject



32
33
34
# File 'lib/converse/comms/mysql/mysql_conversation.rb', line 32

def ask
  converse
end

#connectObject



19
20
21
22
23
24
25
# File 'lib/converse/comms/mysql/mysql_conversation.rb', line 19

def connect()
  @client = Mysql2::Client.new(:host => @host,
                               :port => @port.to_f,
                               :username => @username,
                               :password => @password,
                               :database => @database)
end

#converseObject



27
28
29
30
# File 'lib/converse/comms/mysql/mysql_conversation.rb', line 27

def converse
  connect()
  @client.query(@query)
end

#sayObject



36
37
38
# File 'lib/converse/comms/mysql/mysql_conversation.rb', line 36

def say
  converse
end