lib/scrivito/obj_collection.rb in scrivito_sdk-0.60.0 vs lib/scrivito/obj_collection.rb in scrivito_sdk-0.65.0.rc1
- old
+ new
@@ -13,21 +13,21 @@
# If the parameter is an Array containing ids, return a list of corresponding Objs.
# @param [String, Integer, Array<String, Integer>]id_or_list
# @return [Obj, Array<Obj>]
# @api public
def find(id_or_list)
- find_filtering_deleted(id_or_list, false)
+ find_using(id_or_list, :find_by)
end
# Find a {BasicObj 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.
# @param [String, Integer, Array<String, Integer>]id_or_list
# @return [Obj, Array<Obj>]
# @api public
def find_including_deleted(id_or_list)
- find_filtering_deleted(id_or_list, true)
+ find_using(id_or_list, :find_by_including_deleted)
end
# Find the {BasicObj Obj} with the given path.
# Returns +nil+ if no matching Obj exists.
# @param [String] path Path of the {BasicObj Obj}.
@@ -96,31 +96,30 @@
.include_deleted
end
private
- def find_filtering_deleted(id_or_list, include_deleted)
+ def find_using(id_or_list, method)
case id_or_list
when Array
- find_by(:id, id_or_list, include_deleted).map(&:first).compact
+ send(method, :id, id_or_list).map(&:first).compact
else
- obj = find_by(:id, [id_or_list.to_s], include_deleted).first.first
+ obj = send(method, :id, [id_or_list.to_s]).first.first
+
obj or raise ResourceNotFound, "Could not find Obj with id #{id_or_list}"
end
end
- # accepts the name of an "obj_by" - view, a list of keys
- # and an "include_deleted" flag
- # returns a list of lists of Objs: a list of Objs for each given keys.
- def find_by(view, keys, include_deleted = false)
- if include_deleted
- finder_method_name = :find_obj_data_including_deleted_by
- else
- finder_method_name = :find_obj_data_by
+ def find_by(view, keys)
+ find_by_including_deleted(view, keys).map do |list|
+ list.reject(&:deleted?)
end
+ end
- result = CmsBackend.instance.public_send(
- finder_method_name,
+ # accepts the name of an "obj_by" - view, a list of keys
+ # returns a list of lists of Objs: a list of Objs for each given keys.
+ def find_by_including_deleted(view, keys)
+ result = CmsBackend.instance.find_obj_data_by(
workspace.revision,
view,
keys)
result.map do |list|