Module: Poro::Context::FindMethods

Included in:
Poro::Context
Defined in:
lib/poro/context.rb

Overview

A mixin that contains all the context find methods.

The methods are split into three groups:

FindMethods

Contains the methods that a developer should use but that a Context author should never need to override.

FindMethods::RootMethods

Contains the methods that a developer should never need to use, but that a Context author needs to override.

FindMethods::HelperMethods

Some private helper methods that rarely need to be used or overriden.

Note that fetch is considered basic functionality and not a find method, even though it technically finds by id.

Subclasses are expected to override the methods in RootMethods.

Defined Under Namespace

Modules: HelperMethods, RootMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(mod) ⇒ Object

:nodoc:



228
229
230
231
232
233
# File 'lib/poro/context.rb', line 228

def self.included(mod) # :nodoc:
  mod.send(:include, RootMethods)
  mod.send(:private, *RootMethods.instance_methods)
  mod.send(:include, HelperMethods)
  mod.send(:private, *HelperMethods.instance_methods)
end

Instance Method Details

#data_store_find(first_or_all, *args, &block) ⇒ Object

Forwards the arguments and any block to the data store’s find methods, and returns plain ol’ objects as the result.

WARNING: This normally should not be used as its behavior is dependent upon the underlying data store, however sometimes there is no equivalent to the functionality offered by the data store given by the normal find method.

The first argument must be one of:

  • :all or :many

  • :first or :one



458
459
460
461
462
463
464
465
466
# File 'lib/poro/context.rb', line 458

def data_store_find(first_or_all, *args, &block)
  if(first_or_all == :all || first_or_all == :many)
    return data_store_find_all(*args, &block)
  elsif( first_or_all == :first || first_or_all == :one)
    return data_store_find_first(*args, &block)
  else
    raise ArgumentError, "#{__method__} expects the first argument to be one of :all, :many, :first, or :one."
  end
end

#find(arg, opts = {}) ⇒ Object

Fetches records according to the parameters given in opts.

Contexts attempt to implement this method as uniformily as possible, however some features only exist in some backings and may or may not be portable.

WARNING: For performance, some Contexts may not check that the passed options are syntactically correct before passing off to their data store. This could result in the inadvertent support of some underlying functionality that may go away in a refactor. Please make sure you only use this method in the way it is documented for maximal future compatibility.

Note that if you wish to work more directly with the data store’s find methods, one should see <ttdata_store_find_all</tt> and data_store_find_first.

The first argument must be one of the following:

  • An ID

  • An array of IDs

  • :all or :many

  • :first or :one

The options are as follows:

:conditions

A hash of key-value pairs that will be matched against. They are joined by an “and”. Note that in contexts that support embedded contexts, the keys may be dot separated keypaths.

:order

The name of the key to order by in ascending order, an array of keys to order by in ascending order, an array of arrays, or a hash, where the first value is the key, and the second value is either :asc or :desc.

:limit

Either the limit of the number of records to get, an array of the limit and offset, or a hash with keys :limit and/or :offset.

Subclassing

Subclasses MUST NOT override this method.

This method delegates out its calls to other methods that should be overridden by subclasses.



435
436
437
438
439
440
441
442
443
444
445
# File 'lib/poro/context.rb', line 435

def find(arg, opts={})
  if(arg == :all || arg == :many)
    return find_all(opts)
  elsif( arg == :first || arg == :one)
    return find_first(opts)
  elsif( arg.respond_to?(:map) )
    return find_with_ids(arg)
  else
    return fetch(arg)
  end
end