Module: Cylons::RPC
- Extended by:
- ActiveSupport::Concern
- Includes:
- ActiveModel::Dirty, Attributes
- Included in:
- Service
- Defined in:
- lib/cylons/rpc.rb
Instance Method Summary
collapse
Methods included from Attributes
#read_attribute, #write_attribute
Instance Method Details
#all ⇒ Object
need to wrap because to_a will leak connections otherwise
8
9
10
11
12
|
# File 'lib/cylons/rpc.rb', line 8
def all
::ActiveRecord::Base.connection_pool.with_connection do
execute(:all).to_a
end
end
|
#create(params) ⇒ Object
14
15
16
|
# File 'lib/cylons/rpc.rb', line 14
def create(params)
execute(:create, params)
end
|
#destroy(id) ⇒ Object
18
19
20
|
# File 'lib/cylons/rpc.rb', line 18
def destroy(id)
execute(:destroy, id)
end
|
#execute(rpc_method, *args) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/cylons/rpc.rb', line 22
def execute(rpc_method, *args)
puts Thread.current.object_id
::ActiveRecord::Base.connection_pool.with_connection do
puts ::ActiveRecord::Base.connection_pool.instance_variable_get("@connections").size
begin
if args.any?
@last_response = self.class.model.send(rpc_method.to_sym, *args)
else
@last_response = self.class.model.send(rpc_method.to_sym)
end
@last_response
rescue => e
puts e.inspect
@last_response = {:error => e.message}
end
end
end
|
#find(id) ⇒ Object
42
43
44
|
# File 'lib/cylons/rpc.rb', line 42
def find(id)
execute(:find, id)
end
|
#first ⇒ Object
46
47
48
|
# File 'lib/cylons/rpc.rb', line 46
def first
execute(:first)
end
|
#first_or_create(params) ⇒ Object
50
51
52
|
# File 'lib/cylons/rpc.rb', line 50
def first_or_create(params)
execute(:first_or_create, params)
end
|
#last ⇒ Object
54
55
56
|
# File 'lib/cylons/rpc.rb', line 54
def last
execute(:last)
end
|
#save(id = nil, attributes) ⇒ Object
66
67
68
69
70
71
72
|
# File 'lib/cylons/rpc.rb', line 66
def save(id = nil, attributes)
if(id)
execute(:update, id, attributes)
else
execute(:create, attributes)
end
end
|
#scope_by(params) ⇒ Object
62
63
64
|
# File 'lib/cylons/rpc.rb', line 62
def scope_by(params)
execute(:scope_by, params)
end
|
#search(params) ⇒ Object
58
59
60
|
# File 'lib/cylons/rpc.rb', line 58
def search(params)
response = execute(:search, params)
end
|
#update(attributes) ⇒ Object
74
75
76
|
# File 'lib/cylons/rpc.rb', line 74
def update(attributes)
execute(:update, attributes.keys, attributes.values)
end
|