Class: Vanity::Adapters::ActiveRecordAdapter::VanityRecord

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/vanity/adapters/active_record_adapter.rb

Overview

Base model, stores connection and defines schema

Class Method Summary collapse

Class Method Details

.needs_attr_accessible?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/vanity/adapters/active_record_adapter.rb', line 17

def self.needs_attr_accessible?
  respond_to?(:attr_accessible) && (!defined?(ActionController::StrongParameters) || defined?(ProtectedAttributes))
end

.rails_agnostic_find_or_create_by(method, value) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/vanity/adapters/active_record_adapter.rb', line 21

def self.rails_agnostic_find_or_create_by(method, value)
  retried = false
  begin
    if respond_to? :find_or_create_by
      find_or_create_by(method => value)
    else
      send :"find_or_create_by_#{method}", value
    end
  rescue ActiveRecord::RecordNotUnique
    if retried
      raise
    else
      retried = true
      retry
    end
  end
end