Module: ActiveRecord::Acts::ActsAsReadonlyable::ClassMethods::FinderClassOverrides

Defined in:
lib/acts_as_readonlyable.rb

Instance Method Summary collapse

Instance Method Details

#calculate(operation, column_name, options = {}) ⇒ Object



96
97
98
99
100
101
# File 'lib/acts_as_readonlyable.rb', line 96

def calculate(operation, column_name, options = {})
  run_on_db(options) do
    options.delete(:readonly)
    super
  end
end

#construct_finder_sql(options) ⇒ Object



80
81
82
# File 'lib/acts_as_readonlyable.rb', line 80

def construct_finder_sql(options)
  options.merge(:sql => super)
end

#count_by_sql(sql, options = nil) ⇒ Object



76
77
78
# File 'lib/acts_as_readonlyable.rb', line 76

def count_by_sql(sql, options = nil)
  run_on_db(options) { super(sql) }
end

#find_by_sql(sql, options = nil) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/acts_as_readonlyable.rb', line 64

def find_by_sql(sql, options = nil) 
  
  # Called through construct_finder_sql
  if sql.is_a?(Hash)
    options = sql
    sql = sql[:sql]
  end
  
  run_on_db(options) { super(sql) }
  
end

#find_every(options) ⇒ Object



60
61
62
# File 'lib/acts_as_readonlyable.rb', line 60

def find_every(options)
  run_on_db(options) { super }
end

#set_readonly_option!(options) ⇒ Object

:nodoc:



84
85
86
87
88
89
90
91
92
93
94
# File 'lib/acts_as_readonlyable.rb', line 84

def set_readonly_option!(options) #:nodoc:
  # Inherit :readonly from finder scope if set.  Otherwise,
  # if :joins is not blank then :readonly defaults to true.
  unless options.has_key?(:readonly)
    if scoped?(:find, :readonly)
      options[:readonly] = true if scope(:find, :readonly)
    elsif !options[:joins].blank? && !options[:select]
      options[:readonly] = true
    end
  end
end