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

Defined in:
lib/acts_as_readonlyable.rb

Instance Method Summary collapse

Instance Method Details

#construct_finder_sql(options) ⇒ Object



73
74
75
# File 'lib/acts_as_readonlyable.rb', line 73

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

#count_by_sql(sql, options = nil) ⇒ Object



69
70
71
# File 'lib/acts_as_readonlyable.rb', line 69

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

#find_by_sql(sql, options = nil) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/acts_as_readonlyable.rb', line 57

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



53
54
55
# File 'lib/acts_as_readonlyable.rb', line 53

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

#set_readonly_option!(options) ⇒ Object

:nodoc:



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/acts_as_readonlyable.rb', line 77

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