@@ -25,12 +25,12 @@ def initialize(model, options={})
2525 end
2626
2727 def earliest
28- earliest_obj = model . find ( :first , : order => "#{ timestamp_field } asc" )
28+ earliest_obj = model . order ( "#{ timestamp_field } asc" ) . first
2929 earliest_obj . nil? ? Time . at ( 0 ) : earliest_obj . send ( timestamp_field )
3030 end
3131
3232 def latest
33- latest_obj = model . find ( :first , : order => "#{ timestamp_field } desc" )
33+ latest_obj = model . order ( "#{ timestamp_field } desc" ) . first
3434 latest_obj . nil? ? Time . now : latest_obj . send ( timestamp_field )
3535 end
3636 # A model class is expected to provide a method Model.sets that
@@ -46,15 +46,15 @@ def find(selector, options={})
4646 options [ :resumption_token ] ) if options [ :resumption_token ]
4747 conditions = sql_conditions ( options )
4848 if :all == selector
49- total = find_scope . count ( :id , : conditions => conditions )
49+ total = find_scope . where ( conditions ) . count
5050 if @limit && total > @limit
5151 select_partial ( find_scope ,
5252 ResumptionToken . new ( options . merge ( { :last => 0 } ) ) )
5353 else
54- find_scope . find ( :all , :conditions => conditions )
54+ find_scope . where ( conditions )
5555 end
5656 else
57- find_scope . find ( selector , :conditions => conditions )
57+ find_scope . where ( conditions ) . find ( selector )
5858 end
5959 end
6060
@@ -90,19 +90,19 @@ def find_scope(options)
9090
9191 # Find the set or return an empty scope
9292 set = find_set_by_spec ( options [ :set ] )
93- return model . scoped ( : limit => 0 ) if set . nil?
93+ return model . limit ( 0 ) if set . nil?
9494
9595 # If the set has a backward relationship, we'll use it
9696 if set . class . respond_to? ( :reflect_on_all_associations )
9797 set . class . reflect_on_all_associations . each do |assoc |
98- return set . send ( assoc . name ) . scoped if assoc . klass == model
98+ return set . send ( assoc . name ) if assoc . klass == model
9999 end
100100 end
101101
102102 # Search the attributes for 'set'
103103 if model . column_names . include? ( 'set' )
104104 # Scope using the set attribute as the spec
105- model . scoped ( :conditions => { :set => options [ :set ] } )
105+ model . where ( set : options [ :set ] )
106106 else
107107 # Default to empty set, as we've tried everything else
108108 model . scoped ( :limit => 0 )
@@ -122,24 +122,23 @@ def next_set(find_scope, token_string)
122122 raise OAI ::ResumptionTokenException . new unless @limit
123123
124124 token = ResumptionToken . parse ( token_string )
125- total = find_scope . count ( :id , :conditions => token_conditions ( token ) )
125+ total = find_scope . where ( token_conditions ( token ) ) . count
126126
127127 if @limit < total
128128 select_partial ( find_scope , token )
129129 else # end of result set
130- find_scope . find ( :all ,
131- :conditions => token_conditions ( token ) ,
132- :limit => @limit , : order => "#{ model . primary_key } asc" )
130+ find_scope . where ( token_conditions ( token ) )
131+ . limit ( @limit )
132+ . order ( "#{ model . primary_key } asc" )
133133 end
134134 end
135135
136136 # select a subset of the result set, and return it with a
137137 # resumption token to get the next subset
138138 def select_partial ( find_scope , token )
139- records = find_scope . find ( :all ,
140- :conditions => token_conditions ( token ) ,
141- :limit => @limit ,
142- :order => "#{ model . primary_key } asc" )
139+ records = find_scope . where ( token_conditions ( token ) )
140+ . limit ( @limit )
141+ . order ( "#{ model . primary_key } asc" )
143142 raise OAI ::ResumptionTokenException . new unless records
144143 offset = records . last . send ( model . primary_key . to_sym )
145144
0 commit comments