Sha256: 825c23c5f95b7f908b02d9be6aeca92a6064a5a119e406f6953be0a2d915c776

Contents?: true

Size: 1.97 KB

Versions: 14

Compression:

Stored size: 1.97 KB

Contents

module RailsConnector

  # This class provides methods used to retrieve objects from CMS based an entry
  # in CMS of the obj_class <tt>NamedLink</tt>.
  # @api public
  class NamedLink

    # @api public
    class NotFound < StandardError
    end

    @@named_links_cache = nil

    # Generates a cache of named links based on the CMS objects related link list.
    # Raises exceptions if zero or more than one objects have this obj_class
    def self.generate_named_links_cache
      return if @@named_links_cache

      found_object = find_named_link_obj
      if found_object.nil?
        raise NotFound, "Couldn't find NamedLink CMS Object!"
      else
        @@named_links_cache = found_object.
          related_links.
          flatten(1).
          each_with_object({}) do |link_obj, temp|
            temp[link_obj.title] = link_obj.destination_object
          end
      end

      return nil
    end

    # This method will be called to retrieve the NamedLink Obj.
    # By default it will look for the Obj at the path "_named_links".
    # Overwrite this method only if you know what you are doing.
    # @api public
    def self.find_named_link_obj
      Obj.find_by_path("/_named_links")
    end

    def self.cache_expiry_time=(value)
      raise "NamedLink.cache_expiry_time is deprecated. NamedLink no longer has a separate cache."
    end

    def self.cache_expired?
      true
    end

    # Returns the CMS object mapped to the given title or nil.
    # The title can be a string of symbol.
    # @api public
    def self.get_object(title, options = {})
      object = named_links[title.to_s]
      raise NotFound, "The NamedLink '#{title.to_s}' does not exist" if object.nil?
      object
    end

    def self.reset_cache
      @@named_links_cache = nil
    end

    def self.named_links
      reset_cache if cache_expired?
      generate_named_links_cache unless named_links_cache
      named_links_cache
    end

    def self.named_links_cache
      @@named_links_cache
    end

  end

end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
infopark_cloud_connector-6.8.1.26.236500544 lib/rails_connector/named_link.rb
infopark_cloud_connector-6.8.1 lib/rails_connector/named_link.rb
infopark_cloud_connector-6.8.0.539.93842523 lib/rails_connector/named_link.rb
infopark_cloud_connector-6.8.0.529.114081979 lib/rails_connector/named_link.rb
infopark_cloud_connector-6.8.0.518.30999728 lib/rails_connector/named_link.rb
infopark_cloud_connector-6.8.0.515.34928522 lib/rails_connector/named_link.rb
infopark_cloud_connector-6.8.0.498.46559598 lib/rails_connector/named_link.rb
infopark_cloud_connector-6.8.0.480.261594408 lib/rails_connector/named_link.rb
infopark_cloud_connector-6.8.0.444.171626367 lib/rails_connector/named_link.rb
infopark_cloud_connector-6.8.0.406.131718077 lib/rails_connector/named_link.rb
infopark_cloud_connector-6.8.0.356.19698103 lib/rails_connector/named_link.rb
infopark_cloud_connector-6.8.0.348.160665197 lib/rails_connector/named_link.rb
infopark_cloud_connector-6.8.0.328.4a753fc lib/rails_connector/named_link.rb
infopark_cloud_connector-6.8.0.322.c003f11 lib/rails_connector/named_link.rb