Class: Ca::DataStore::Ar::Provider

Inherits:
Object
  • Object
show all
Includes:
TR::CondUtils, TeLogger::TeLogHelper
Defined in:
lib/ca/data_store/ar/provider.rb

Class Method Summary collapse

Class Method Details

.handle(*args, &block) ⇒ Object



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
      # ignored
    when :is_new_record?
      target.new_record?
    else
      raise ProviderException, "Unknown operation '#{ops}'" 
    end

  end
end

.provider_keyObject



18
19
20
# File 'lib/ca/data_store/ar/provider.rb', line 18

def self.provider_key
  :cads_ar
end

.provider_nameObject



14
15
16
# File 'lib/ca/data_store/ar/provider.rb', line 14

def self.provider_name
  "ActiveRecord Provider"
end