Module: Poro::Context::FindMethods::RootMethods

Defined in:
lib/poro/context.rb

Overview

Provides the delegate methods for the find routines.

These methods are made private so that developers use the main find methods. This makes it easier to change behavior in the future due to the bottlenecking.

Subclasses of Context should override all of these. See the inline subclassing documentation sections for each method for details.

Instance Method Summary collapse

Instance Method Details

#data_store_find_all(*args, &block) ⇒ Object

Calls the relevant finder method on the underlying data store, and converts all the results to plain objects.

One usually calls thrigh through the data_store_find method with the :all or :many arument.

Use of this method is discouraged as being non-portable, but sometimes there is no alternative but to get right down to the underlying data store.

Note that if this method still isn’t enough, you’ll have to use the data store and convert the objects yourself, like so:

SomeContext.data_store.find_method(arguments).map {{|data| SomeContext.convert_to_plain_object(data)}

Subclassing

Subclasses MUST override this method.

Subclasses are expected to return the results converted to plain objects using

self.convert_to_plain_object(data)


299
300
301
# File 'lib/poro/context.rb', line 299

def data_store_find_all(*args, &block)
  return [].map {|data| convert_to_plain_object(data)}
end

#data_store_find_first(*args, &block) ⇒ Object

Calls the relevant finder method on the underlying data store, and converts the result to a plain object.

One usually calls thrigh through the data_store_find method with the :first or :one arument.

Use of this method is discouraged as being non-portable, but sometimes there is no alternative but to get right down to the underlying data store.

Note that if this method still isn’t enough, you’ll have to use the data store and convert the object yourself, like so:

SomeContext.convert_to_plain_object( SomeContext.data_store.find_method(arguments) )

Subclassing

Subclasses MUST override this method.

Subclasses are expected to return the result converted to a plain object using

self.convert_to_plain_object(data)


324
325
326
# File 'lib/poro/context.rb', line 324

def data_store_find_first(*args, &block)
  return convert_to_plain_object(nil)
end

#find_all(opts) ⇒ Object

Returns an array of all the records that match the following options.

One ususally calls this through find via the :all or :many argument.

See find for more help.

Subclassing

Subclasses MUST override this method.

Subclases usually convert the options into a call to data_store_find_all.



256
257
258
# File 'lib/poro/context.rb', line 256

def find_all(opts)
  return data_store_find_all(opts)
end

#find_first(opts) ⇒ Object

Returns the first record that matches the following options. Use of fetch is more convenient if finding by ID.

One usually calls this through find via the :first or :one argument.

See find for more help.

Subclassing

Subclasses MUST override this method!

They usually take one of several tacts:

  1. Convert tothe options and call data_store_find_first.

  2. Set the limit to 1 and call find_all.



274
275
276
277
# File 'lib/poro/context.rb', line 274

def find_first(opts)
  hashize_limit(opts[:limit])[:limit] = 1
  return find_all(opts)
end

#find_with_ids(*ids) ⇒ Object

Returns the records that correspond to the passed ids (or array of ids).

One usually calls this by giving an array of IDs to the find method.

Subclassing

Subclasses SHOULD override this method.

By default, this method aggregates separate calls to fetch. For most data stores this makes N calls to the server, decreasing performance.

When possible, this method should be overriden by subclasses to be more efficient, probably calling a find_all with the IDs, as filtered by the clean_id private method.



342
343
344
345
# File 'lib/poro/context.rb', line 342

def find_with_ids(*ids)
  ids = ids.flatten
  return ids.map {|id| fetch(id)}
end