require 'fiona7/super_id_finder' # This class allows to access objects linking to # given object, i.e. super objects # # It provides two modes of searching: preview nad live module Fiona7 class SuperObjectFinder def initialize(model=::Fiona7::WriteObj, connection=nil, instance_name=RailsConnector::CmsBaseModel.instance_name) @instance_name = instance_name @conn = connection || model.connection @model = model @id_finder = SuperIdFinder.new([], [], @conn, @instance_name) end def find(type=:preview, obj) case type when :preview preview(obj) when :live live(obj) else raise ArgumentError, "Uknown type #{type.inspect} expected :preview or :live" end end # This method returns the results of search for objects # in preview mode. # # This means that all objects that are reachable in preview # are returned (unreleased, commited etc.) def preview(obj) ids = @id_finder.preview([obj.obj_id]) @model.find(ids).select(&:exportable?) end # This method returns the results of search for objects # in live mode. # # This means that only the objects that are reachable in # live are returned, i.e. avaiable for outside world def live(obj) ids = @id_finder.live([obj.obj_id]) @model.find(ids).select(&:exportable?) end end end