Module: Clientele::Resource::Pagination

Defined in:
lib/clientele/resource/pagination.rb

Defined Under Namespace

Modules: Iterator

Instance Method Summary collapse

Instance Method Details

#paginate(method_name, &implementation) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/clientele/resource/pagination.rb', line 5

def paginate(method_name, &implementation)
  mixin = Module.new do
     define_method method_name do |*args, &block|
      super(*args, &block).tap do |request|
        request.extend(Enumerable) unless request.kind_of? Enumerable
        request.extend(Iterator)
        request.class_eval(&default_implementation)
        request.class_eval(&implementation) if implementation
      end
    end
  end
  const_set :"#{method_name.to_s.capitalize}Pagination", mixin
  singleton_class.prepend mixin
end