Method: Box::Folder#find

Defined in:
lib/box/folder.rb

#find(criteria) ⇒ Array

Note:

The recursive option will call #tree, which can be slow for large folders.

Note:

Any item method (as a symbol) can be used as criteria, which could cause major problems if used improperly.

Search for sub-items using criteria.

TODO: Lookup YARD syntax for options hash.

Examples:

Find all sub-items with the name ‘README’

folder.search(:name => 'README')

Recusively find a sub-item with the given path.

folder.search(:path => '/test/file.mp4', :recursive => true)

Recursively find all files with a given sha1.

folder.search(:type => 'file', :sha1 => 'abcdefg', :recursive => true)

Parameters:

  • criteria (Hash)

    The hash of criteria to use. Each key of the criteria will be called on each sub-item and tested for equality. This lets you use any method of Item, Box::Folder, and Box::File as the criteria.

Returns:

  • (Array)

    An array of all sub-items that matched the criteria.



95
96
97
98
99
100
101
102
# File 'lib/box/folder.rb', line 95

def find(criteria)
  recursive = criteria.delete(:recursive)
  recursive = false if recursive == nil # default to false for performance reasons

  tree if recursive # get the full tree

  find!(criteria, recursive)
end