Class: Scrivito::ObjCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/scrivito/obj_collection.rb

Overview

This class allows you to retrieve Objects from a specific working copy. You can get an instance by accessing Workspace#objs.

Instance Method Summary collapse

Instance Method Details

#allObjSearchEnumerator

Returns a Scrivito::ObjSearchEnumerator of all Objs.

Returns:



68
69
70
# File 'lib/scrivito/obj_collection.rb', line 68

def all
  ObjSearchEnumerator.new(workspace).batch_size(1000)
end

#find(id_or_list) ⇒ Obj+

Find a Obj by its id. If the parameter is an Array containing ids, return a list of corresponding Objs.

Parameters:

  • id_or_list (String, Integer, Array<String, Integer>)

Returns:



17
18
19
# File 'lib/scrivito/obj_collection.rb', line 17

def find(id_or_list)
  find_filtering_deleted(id_or_list, false)
end

#find_all_by_obj_class(obj_class) ⇒ ObjSearchEnumerator

Returns a Scrivito::ObjSearchEnumerator of all Objs with the given obj_class.

Parameters:

  • obj_class (String)

    Name of the ObjClass.

Returns:



76
77
78
# File 'lib/scrivito/obj_collection.rb', line 76

def find_all_by_obj_class(obj_class)
  all.and(:_obj_class, :equals, obj_class)
end

#find_by_path(path) ⇒ Obj

Find the Obj with the given path. Returns nil if no matching Obj exists.

Parameters:

  • path (String)

    Path of the Obj.

Returns:



36
37
38
# File 'lib/scrivito/obj_collection.rb', line 36

def find_by_path(path)
  find_by(:path, [path]).first.first
end

Returns the Obj with the given permalink, or nil if no matching Obj exists.

Parameters:

  • permalink (String)

    The permalink of the Obj.

Returns:



44
45
46
# File 'lib/scrivito/obj_collection.rb', line 44

def find_by_permalink(permalink)
  find_by(:permalink, [permalink]).first.first
end

#find_including_deleted(id_or_list) ⇒ Obj+

Find a Obj by its id. If the parameter is an Array containing ids, return a list of corresponding Objs. The results include deleted objects as well.

Parameters:

  • id_or_list (String, Integer, Array<String, Integer>)

Returns:



27
28
29
# File 'lib/scrivito/obj_collection.rb', line 27

def find_including_deleted(id_or_list)
  find_filtering_deleted(id_or_list, true)
end

#where(field, operator, value, boost = nil) ⇒ ObjSearchEnumerator

Returns a Scrivito::ObjSearchEnumerator with the given initial subquery consisting of the four arguments.

Note that field and value can also be arrays for searching several fields or searching for several values.

Scrivito::ObjSearchEnumerators can be chained using one of the chainable methods (e.g. Scrivito::ObjSearchEnumerator#and and Scrivito::ObjSearchEnumerator#and_not).

Parameters:

Returns:



60
61
62
63
# File 'lib/scrivito/obj_collection.rb', line 60

def where(field, operator, value, boost = nil)
  ObjSearchEnumerator.new(workspace)
    .and(field, operator, value, boost)
end