Sha256: c333a45766b85c185f4ef83e78e2ba00475c321fb7e575b71d0794955a3c4b88

Contents?: true

Size: 1.42 KB

Versions: 3

Compression:

Stored size: 1.42 KB

Contents

module ActsAsFavoritor #:nodoc:
    module FavoriteScopes

        # returns favorite records where favoritor is the record passed in.
        def for_favoritor favoritor
            where favoritor_id: favoritor.id, favoritor_type: parent_class_name(favoritor)
        end

        # returns favorite records where favoritable is the record passed in.
        def for_favoritable favoritable
            where favoritable_id: favoritable.id, favoritable_type: parent_class_name(favoritable)
        end

        # returns favorite records where favoritor_type is the record passed in.
        def for_favoritor_type favoritor_type
            where favoritor_type: favoritor_type
        end

        # returns favorite records where favoritable_type is the record passed in.
        def for_favoritable_type favoritable_type
            where favoritable_type: favoritable_type
        end

        # returns favorite records from past 2 weeks with default parameter.
        def recent from
            where ['created_at > ?', (from || 2.weeks.ago).to_s(:db)]
        end

        # returns favorite records in descending order.
        def descending
            order 'favorites.created_at desc'
        end

        # returns unblocked favorite records.
        def unblocked
            where blocked: false
        end

        # returns blocked favorite records.
        def blocked
            where blocked: true
        end

    end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
acts_as_favoritor-1.0.2 lib/acts_as_favoritor/favorite_scopes.rb
acts_as_favoritor-1.0.1 lib/acts_as_favoritor/favorite_scopes.rb
acts_as_favoritor-1.0.0 lib/acts_as_favoritor/favorite_scopes.rb