Module: GroupDocs::Extensions::Lookup

Included in:
Document, Storage::File, Storage::Folder
Defined in:
lib/groupdocs/extensions/lookup.rb

Overview

Extends classes providing them with .find! and .find_all! class methods which is a bit of sugar for working with files, folder and documents,

It’s not that flexible because requires extending class to implement .all! class method.

This module is a subject to modifications.

Instance Method Summary collapse

Instance Method Details

#find!(attribute, value, access = {}) ⇒ GroupDocs::Api::Entity

Returns first object matching given options.

Parameters:

  • attribute (Symbol)
  • value (Integer, String, Regexp)
  • access (Hash) (defaults to: {})

    Access credentials

Options Hash (access):

  • :client_id (String)
  • :private_key (String)

Returns:



24
25
26
# File 'lib/groupdocs/extensions/lookup.rb', line 24

def find!(attribute, value, access = {})
  find_all!(attribute, value, access).first
end

#find_all!(attribute, value, access = {}) ⇒ Array

Returns all objects matching given options.

Each entity has to implement #all! method for this to work.

Parameters:

  • attribute (Symbol)
  • value (Integer, String, Regexp)
  • access (Hash) (defaults to: {})

    Access credentials

Options Hash (access):

  • :client_id (String)
  • :private_key (String)

Returns:

  • (Array)

    Array of matching entities

Raises:

  • (NoMethodError)

    if extending class does not implement .all! class method.



42
43
44
45
46
47
48
# File 'lib/groupdocs/extensions/lookup.rb', line 42

def find_all!(attribute, value, access = {})
  respond_to?(:all!) or raise NoMethodError, "#{self}.all! is not implemented - aborting."

  all!('/', access).select do |object|
    value === object.send(attribute)
  end
end