22
23
24
25
26
27
28
29
30
31
32
33
34
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
65
|
# File 'lib/ca/data_store/ar/provider.rb', line 22
def self.handle(*args, &block)
ops = args.first
case ops
when :init
conf = args[1]
ActiveRecord::Base.establish_connection(conf[:conn]) if not_empty?(conf[:conn])
ActiveRecord::Base.logger = teLogger
else
target = args[1]
params = args[2..-1]
case ops
when :save
target.save
when :delete
target.destroy
when :find
teLogger.debug "params : #{params.first}"
res = []
res = target.where(params.first) if not_empty?(params.first)
if block
res = block.call(:find_result, target, res)
end
res
when :find_all
res = target.all
if block
res = block.call(:find_all_result, target, res)
end
res
when :schema
when :is_new_record?
target.new_record?
else
raise ProviderException, "Unknown operation '#{ops}'"
end
end
end
|