Class: Believer::Command
- Inherits:
-
Object
show all
- Defined in:
- lib/believer/command.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(attrs = {}) ⇒ Command
Returns a new instance of Command.
6
7
8
9
10
11
|
# File 'lib/believer/command.rb', line 6
def initialize(attrs = {})
attrs.each do |name, value|
send("#{name}=", value)
end if attrs.present?
end
|
Instance Attribute Details
#consistency_level ⇒ Object
Returns the value of attribute consistency_level.
4
5
6
|
# File 'lib/believer/command.rb', line 4
def consistency_level
@consistency_level
end
|
#execution_options ⇒ Object
Returns the value of attribute execution_options.
4
5
6
|
# File 'lib/believer/command.rb', line 4
def execution_options
@execution_options
end
|
#record_class ⇒ Object
Returns the value of attribute record_class.
4
5
6
|
# File 'lib/believer/command.rb', line 4
def record_class
@record_class
end
|
Instance Method Details
#can_execute? ⇒ Boolean
31
32
33
|
# File 'lib/believer/command.rb', line 31
def can_execute?
true
end
|
#clone ⇒ Object
13
14
15
|
# File 'lib/believer/command.rb', line 13
def clone
self.class.new(query_attributes)
end
|
#command_name ⇒ Object
27
28
29
|
# File 'lib/believer/command.rb', line 27
def command_name
self.class.name.split('::').last.underscore
end
|
#consistency(level) ⇒ Object
17
18
19
20
21
|
# File 'lib/believer/command.rb', line 17
def consistency(level)
c = clone
c.consistency_level = level
c
end
|
#execute(name = nil) ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/believer/command.rb', line 35
def execute(name = nil)
return false unless can_execute?
@record_class.connection_pool.with do |connection|
cql = to_cql
begin
name = "#{record_class.name} #{command_name}" if name.nil?
return ActiveSupport::Notifications.instrument('cql.believer', :cql => cql, :name => name) do
exec_opts = execution_options || {}
begin
return connection.execute(cql, exec_opts)
rescue Cql::NotConnectedError => not_connected
connection.connect
return connection.execute(cql, exec_opts)
end
end
rescue Cql::Protocol::DecodingError => e
@record_class.reset_connection(connection)
raise e
end
end
end
|
#query_attributes ⇒ Object
23
24
25
|
# File 'lib/believer/command.rb', line 23
def query_attributes
{:record_class => @record_class, :consistency_level => @consistency_level}
end
|