Sha256: 2877d07886617dfae77213090450e9ee2c94b94b94867d31728971dfe16a34bd

Contents?: true

Size: 1.13 KB

Versions: 31

Compression:

Stored size: 1.13 KB

Contents

module DuckPuncher
 module Ducks
   module ActiveRecord
     def self.included(base)
       base.extend(ClassMethods)
     end

     def associations?
       associations.present?
     end

     def associations
       reflections.select { |key, _| send(key).present? rescue nil }.keys
     end

     module ClassMethods
       def except_for(*ids)
         scoped.where("#{quoted_table_name}.id NOT IN (?)", ids)
       end

       def since(time)
         scoped.where("#{quoted_table_name}.created_at > ?", time)
       end

       alias created_since since

       def before(time)
         scoped.where("#{quoted_table_name}.created_at < ?", time)
       end

       def updated_since(time)
         scoped.where("#{quoted_table_name}.updated_at > ?", time)
       end

       def between(start_at, end_at)
         scoped.where("#{quoted_table_name}.created_at BETWEEN ? AND ", start_at, end_at)
       end

       def latest
         scoped.order("#{quoted_table_name}.id ASC").last
       end

       # shim for backwards compatibility with Rails 3
       def scoped
         where(nil)
       end if Rails::VERSION::MAJOR != 3
     end
   end
 end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
duck_puncher-4.4.1 lib/duck_puncher/ducks/active_record.rb
duck_puncher-4.4.0 lib/duck_puncher/ducks/active_record.rb
duck_puncher-4.3.1 lib/duck_puncher/ducks/active_record.rb
duck_puncher-4.3.0 lib/duck_puncher/ducks/active_record.rb
duck_puncher-4.2.3 lib/duck_puncher/ducks/active_record.rb
duck_puncher-4.2.2 lib/duck_puncher/ducks/active_record.rb
duck_puncher-4.2.1 lib/duck_puncher/ducks/active_record.rb
duck_puncher-4.2.0 lib/duck_puncher/ducks/active_record.rb
duck_puncher-4.1.0 lib/duck_puncher/ducks/active_record.rb
duck_puncher-4.0.0 lib/duck_puncher/ducks/active_record.rb
duck_puncher-3.0.0 lib/duck_puncher/ducks/active_record.rb
duck_puncher-2.16.0 lib/duck_puncher/ducks/active_record.rb
duck_puncher-2.15.0 lib/duck_puncher/ducks/active_record.rb
duck_puncher-2.14.1 lib/duck_puncher/ducks/active_record.rb
duck_puncher-2.14.0 lib/duck_puncher/ducks/active_record.rb
duck_puncher-2.13.0 lib/duck_puncher/ducks/active_record.rb
duck_puncher-2.12.1 lib/duck_puncher/ducks/active_record.rb
duck_puncher-2.12.0 lib/duck_puncher/ducks/active_record.rb
duck_puncher-2.11.0 lib/duck_puncher/ducks/active_record.rb
duck_puncher-2.10.2 lib/duck_puncher/ducks/active_record.rb