Sha256: 387c859f7363c2fafb6a2efc1aa427dfd06b9521b3a87a3370fcff1f7b5bdb6c

Contents?: true

Size: 858 Bytes

Versions: 10

Compression:

Stored size: 858 Bytes

Contents

module EventbriteSDK
  # An Empty resource listing, returned on ORM calls from new resources
  class BlankResourceList
    extend Forwardable
    include Enumerable

    def_delegators :@objects, :[], :concat, :each, :empty?, :to_ary

    def initialize(key: nil)
      @key = key
      @objects = []
    end

    %i(
      next_page
      prev_page
      retrieve
    ).each do |method|
      define_method(method) { self }
    end

    def concat(other)
      other.concat(to_ary)
    end

    def page(_num)
      self
    end

    def with_expansion(*_args)
      self
    end

    def to_json(opts = {})
      { @key => [] }.to_json(opts)
    end

    # Blank lists need to respond to the pagination helpers.
    def object_count
      0
    end

    %i(page_count page_number page_size).each do |name|
      define_method(name) { 1 }
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
eventbrite_sdk-3.6.0 lib/eventbrite_sdk/blank_resource_list.rb
eventbrite_sdk-3.4.0 lib/eventbrite_sdk/blank_resource_list.rb
eventbrite_sdk-3.3.1 lib/eventbrite_sdk/blank_resource_list.rb
eventbrite_sdk-3.3.0 lib/eventbrite_sdk/blank_resource_list.rb
eventbrite_sdk-3.2.0 lib/eventbrite_sdk/blank_resource_list.rb
eventbrite_sdk-3.1.6 lib/eventbrite_sdk/blank_resource_list.rb
eventbrite_sdk-3.1.5 lib/eventbrite_sdk/blank_resource_list.rb
eventbrite_sdk-3.1.4 lib/eventbrite_sdk/blank_resource_list.rb
eventbrite_sdk-3.1.3 lib/eventbrite_sdk/blank_resource_list.rb
eventbrite_sdk-3.1.2 lib/eventbrite_sdk/blank_resource_list.rb