class Cyrax::Presenters::BaseCollection

Attributes

collection[R]
options[R]

Public Class Methods

new(collection, options = {}) click to toggle source
# File lib/cyrax/presenters/base_collection.rb, line 5
def initialize(collection, options = {})
  @collection = collection
  @options = options
end

Public Instance Methods

as_json(*args) click to toggle source
# File lib/cyrax/presenters/base_collection.rb, line 23
def as_json(*args)
  presented_collection.as_json(*args)
end
method_missing(method, *args, &block) click to toggle source
Calls superclass method
# File lib/cyrax/presenters/base_collection.rb, line 27
def method_missing(method, *args, &block)
  return super unless collection.respond_to?(method)
  collection.send(method, *args, &block)
end
presented_collection() click to toggle source
# File lib/cyrax/presenters/base_collection.rb, line 13
def presented_collection
  if collection.is_a?(ActiveRecord::Relation)
    collection.to_a
  elsif collection.respond_to?(:all)
    collection.all.to_a
  else
    Array.wrap collection
  end
end