Class: Ambition::Adapters::ActiveRecord::Base

Inherits:
Object
  • Object
show all
Includes:
ActiveRecord::ConnectionAdapters::Quoting
Defined in:
lib/ambition/adapters/active_record/base.rb

Direct Known Subclasses

Select, Slice, Sort

Instance Method Summary collapse

Instance Method Details

#active_connection?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/ambition/adapters/active_record/base.rb', line 40

def active_connection?
  ::ActiveRecord::Base.active_connection_name
end

#dbadapter_nameObject



44
45
46
47
48
# File 'lib/ambition/adapters/active_record/base.rb', line 44

def dbadapter_name
  ::ActiveRecord::Base.connection.adapter_name
rescue ::ActiveRecord::ConnectionNotEstablished
  'Abstract'
end

#quote_column_name(value) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/ambition/adapters/active_record/base.rb', line 32

def quote_column_name(value)
  if active_connection?
    ::ActiveRecord::Base.connection.quote_column_name(value) 
  else
    value.to_s
  end
end

#sanitize(value) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/ambition/adapters/active_record/base.rb', line 9

def sanitize(value)
  if value.is_a? Array
    return value.map { |v| sanitize(v) }.join(', ')
  end

  case value
  when true,  'true'  
    '1'
  when false, 'false' 
    '0'
  when Regexp
    "'#{value.source}'"
  else 
    if active_connection?
      ::ActiveRecord::Base.connection.quote(value) 
    else
      quote(value)
    end
  end
rescue
  "'#{value}'"
end

#statement(*args) ⇒ Object



50
51
52
53
# File 'lib/ambition/adapters/active_record/base.rb', line 50

def statement(*args)
  @statement_instance ||= DatabaseStatements.const_get(dbadapter_name).new
  @statement_instance.send(*args)
end