Class: Scrivito::ObjCollection
- Inherits:
-
Object
- Object
- Scrivito::ObjCollection
- 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
-
#all ⇒ ObjSearchEnumerator
Returns a ObjSearchEnumerator of all Objs.
-
#find(id_or_list) ⇒ Obj+
Find a Obj by its id.
-
#find_all_by_obj_class(obj_class) ⇒ ObjSearchEnumerator
Returns a ObjSearchEnumerator of all Objs with the given
obj_class
. -
#find_by_path(path) ⇒ Obj
Find the Obj with the given path.
-
#find_by_permalink(permalink) ⇒ Obj
Returns the Obj with the given permalink, or
nil
if no matching Obj exists. -
#find_including_deleted(id_or_list) ⇒ Obj+
Find a Obj by its id.
-
#where(field, operator, value, boost = nil) ⇒ ObjSearchEnumerator
Returns a ObjSearchEnumerator with the given initial subquery consisting of the four arguments.
Instance Method Details
#all ⇒ ObjSearchEnumerator
Returns a Scrivito::ObjSearchEnumerator of all Objs.
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.
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
.
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.
36 37 38 |
# File 'lib/scrivito/obj_collection.rb', line 36 def find_by_path(path) find_by(:path, [path]).first.first end |
#find_by_permalink(permalink) ⇒ Obj
Returns the Obj with the given permalink, or nil
if no matching Obj exists.
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.
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).
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 |