Sha256: 3f6dc762547d0d3aab1d1c403146078671a78619832045fb285a7fc5fbb8a844

Contents?: true

Size: 1.22 KB

Versions: 2

Compression:

Stored size: 1.22 KB

Contents

require 'active_support/core_ext/class'

module Espresso
  self.extensions << :collection
  # Represents collection of resources.
  # Used in Espresso::Controller InheritedResources extension
  class Collection < Array
    cattr_accessor :per_page
    self.per_page = 30

    attr_accessor :base, :options, :collection, :search
    protected :base, :options, :collection

    # Initiates a collection of resources
    # @param [AtiveRecord::Base] base Base class having {Espresso::Model} included
    # @param [Hash] options options for building the collection
    # @option options [Number] :page current page number
    # @option options [Number] :per_page per-page limit
    # @option options [Hash] :search conditions for searching
    def initialize(base, options = {})
      @base, @options = base, options
      replace(collection)
    end

  protected
    # All resources in {#base}
    def collection
      @collection ||= base.all(@options)
    end

    # Proxy to {#collection} methods
    def method_missing(method_name, *args)
      collection.send(method_name, *args)
    end
  end
end

if defined? Searchlogic
  require 'espresso/collection/searchlogic'
end

if defined? WillPaginate
  require 'espresso/collection/will_paginate'
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
espresso-framework-0.3.0 lib/espresso/collection.rb
espresso-0.2.1 lib/espresso/collection.rb