Sha256: 39588ca7495de411051f246d343a26809ded2be37c1ba77ba305531ff3cae65f

Contents?: true

Size: 1.62 KB

Versions: 17

Compression:

Stored size: 1.62 KB

Contents

module Shamu
  module Entities
    class ListScope

      # Include paging parsing and attributes. Adds the following attributes
      # to the list scope:
      #
      # ```
      # class UsersListScope < Shamu::Entities::ListScope
      #   include Shamu::Entities::ListScope::Paging
      # end
      #
      # scope = UsersListScope.coerce!( params )
      # scope.page      # => 1
      # scope.per_page # => 25
      # ```
      module Dates

        # ============================================================================
        # @!group Attributes
        #

        # @!attribute since
        # @return [Time] include only records added since the given timestamp.

        # @!attribute until
        # @return [Time] include only records up until the given timestamp.

        # @!attribute default_since
        # @return [Time] default {#since} if not specified.

        # @!attribute default_until
        # @return [Time] default {#until} if not specified.

        #
        # @!endgroup Attributes

        def self.included( base )
          super

          coerce = Time.instance_method( :to_time ) ? :to_time : nil

          base.attribute :since, coerce: coerce, default: ->() { default_since }
          base.attribute :default_since, coerce: coerce, serialize: false
          base.attribute :until, coerce: coerce, default: ->() { default_until }
          base.attribute :default_until, coerce: coerce, serialize: false
        end

        # @return [Boolean] true if the scope is dated.
        def dated?
          !!self.since || !!self.until # rubocop:disable Style/RedundantSelf
        end

      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
shamu-0.0.24 lib/shamu/entities/list_scope/dates.rb
shamu-0.0.21 lib/shamu/entities/list_scope/dates.rb
shamu-0.0.20 lib/shamu/entities/list_scope/dates.rb
shamu-0.0.19 lib/shamu/entities/list_scope/dates.rb
shamu-0.0.18 lib/shamu/entities/list_scope/dates.rb
shamu-0.0.17 lib/shamu/entities/list_scope/dates.rb
shamu-0.0.15 lib/shamu/entities/list_scope/dates.rb
shamu-0.0.14 lib/shamu/entities/list_scope/dates.rb
shamu-0.0.13 lib/shamu/entities/list_scope/dates.rb
shamu-0.0.11 lib/shamu/entities/list_scope/dates.rb
shamu-0.0.9 lib/shamu/entities/list_scope/dates.rb
shamu-0.0.8 lib/shamu/entities/list_scope/dates.rb
shamu-0.0.7 lib/shamu/entities/list_scope/dates.rb
shamu-0.0.5 lib/shamu/entities/list_scope/dates.rb
shamu-0.0.4 lib/shamu/entities/list_scope/dates.rb
shamu-0.0.3 lib/shamu/entities/list_scope/dates.rb
shamu-0.0.2 lib/shamu/entities/list_scope/dates.rb