Module: ConstantTableSaver::ClassMethods
- Defined in:
- lib/constant_table_saver.rb
Instance Method Summary collapse
- #relation ⇒ Object
-
#reset_constant_record_cache! ⇒ Object
Resets the cached records.
Instance Method Details
#relation ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/constant_table_saver.rb', line 57 def relation super.tap do |s| class << s # we implement find_some here because we'd have to use partial string matching to catch # this case in find_by_sql, which would be ugly. (we do the other cases in find_by_sql # because it's simpler & the only place to catch things like association find queries.) def find_some(ids) return super if @values.present? # special cases such as offset and limit ids.collect {|id| find_one(id)} end end end end |
#reset_constant_record_cache! ⇒ Object
Resets the cached records. Remember that this only affects this process, so while this is useful for running tests, it’s unlikely that you can use this in production - you would need to call it on every Rails instance on every Rails server. Don’t use this plugin on if the table isn’t really constant!
52 53 54 55 |
# File 'lib/constant_table_saver.rb', line 52 def reset_constant_record_cache! @constant_record_methods.each {|method_id| (class << self; self; end;).send(:remove_method, method_id)} if @constant_record_methods @cached_records = @cached_records_by_id = @constant_record_methods = @cached_blank_scope = @find_by_sql = nil end |