Class: Scrivito::ObjCollection

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

Overview

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

Instance Method Summary collapse

Instance Method Details

#allObjSearchEnumerator

Returns an Scrivito::ObjSearchEnumerator of all Objs.

Returns:



87
88
89
# File 'lib/scrivito/obj_collection.rb', line 87

def all
  ObjSearchEnumerator.new(workspace, 1000)
end

#find(id_or_list) ⇒ Obj+

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

Parameters:

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

Returns:



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

def find(id_or_list)
  find_using(id_or_list, :find_by)
end

#find_all_by_obj_class(obj_class) ⇒ ObjSearchEnumerator

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

Parameters:

  • obj_class (String)

    name of the object class.

Returns:



95
96
97
# File 'lib/scrivito/obj_collection.rb', line 95

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

#find_by_path(path) ⇒ Scrivito::BasicObj, NilClass

Note:

If there is more than one Obj with the given path, then the Obj with the smallest id will be returned.

Find the Obj that has the given path.

Parameters:

  • path (String)

    Path of the Obj.

Returns:



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

def find_by_path(path)
  find_by(:path, [path]).first.min_by(&:id)
end
Note:

If there is more than one Obj with the given permalink, then the Obj with the smallest id will be returned.

Returns the Obj that has the given permalink.

Parameters:

  • permalink (String)

    The permalink of the Obj.

Returns:

  • (Scrivito::BasicObj)

    if an Obj with the given permalink exists.

  • (NilClass)

    if no Obj with the given permalink exists.



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

def find_by_permalink(permalink)
  find_by(:permalink, [permalink]).first.min_by(&:id)
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 the corresponding Objs. The results include deleted objects as well.

Parameters:

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

Returns:



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

def find_including_deleted(id_or_list)
  find_using(id_or_list, :find_by_including_deleted)
end

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

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

Note that field and value may 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:



79
80
81
82
# File 'lib/scrivito/obj_collection.rb', line 79

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