Class: Ambition::Adapters::ActiveRecord::Base
- Inherits:
-
Object
- Object
- Ambition::Adapters::ActiveRecord::Base
- Includes:
- ActiveRecord::ConnectionAdapters::Quoting
- Defined in:
- lib/ambition/adapters/active_record/base.rb
Instance Method Summary collapse
- #active_connection? ⇒ Boolean
- #dbadapter_name ⇒ Object
- #quote_column_name(value) ⇒ Object
- #sanitize(value) ⇒ Object
- #statement(*args) ⇒ Object
Instance Method Details
#active_connection? ⇒ Boolean
40 41 42 |
# File 'lib/ambition/adapters/active_record/base.rb', line 40 def active_connection? ::ActiveRecord::Base.active_connection_name end |
#dbadapter_name ⇒ Object
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 |