Sha256: 918a3628f2e4cfb17f3f03002ad9333adb15f1a0f2bba6047553e083b2796dea

Contents?: true

Size: 1.39 KB

Versions: 3

Compression:

Stored size: 1.39 KB

Contents

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
infopark_fiona7-1.6.1.1.5 lib/fiona7/super_object_finder.rb
infopark_fiona7-1.6.1.1.1 lib/fiona7/super_object_finder.rb
infopark_fiona7-1.6.1.1.0 lib/fiona7/super_object_finder.rb