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
|
#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
48
49
50
|
# File 'lib/believer/command.rb', line 48
def can_execute?
true
end
|
#clone ⇒ Object
30
31
32
|
# File 'lib/believer/command.rb', line 30
def clone
self.class.new(query_attributes)
end
|
#command_name ⇒ Object
44
45
46
|
# File 'lib/believer/command.rb', line 44
def command_name
self.class.name.split('::').last.underscore
end
|
#consistency(level) ⇒ Object
34
35
36
37
38
|
# File 'lib/believer/command.rb', line 34
def consistency(level)
c = clone
c.consistency_level = level
c
end
|
#execute(name = nil) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/believer/command.rb', line 52
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
|
#execution_options ⇒ Object
13
14
15
16
17
18
19
20
|
# File 'lib/believer/command.rb', line 13
def execution_options
@execution_options ||= {}
exec_global_opts = ::Believer::Base.environment.believer_configuration[:execution]
unless exec_global_opts.nil?
@execution_options.merge!(exec_global_opts.symbolize_keys)
end
@execution_options
end
|
#execution_options=(opts) ⇒ Object
22
23
24
|
# File 'lib/believer/command.rb', line 22
def execution_options=(opts)
execution_options.merge!(opts)
end
|
#override_execution_options(opts = {}) ⇒ Object
26
27
28
|
# File 'lib/believer/command.rb', line 26
def override_execution_options(opts = {})
@execution_options = opts
end
|
#query_attributes ⇒ Object
40
41
42
|
# File 'lib/believer/command.rb', line 40
def query_attributes
{:record_class => @record_class, :consistency_level => @consistency_level}
end
|