Sha256: aa53e79f43ea68c4969326093b1c36d5e15b4e931b2ab2a981801a7344db089d

Contents?: true

Size: 1.96 KB

Versions: 21

Compression:

Stored size: 1.96 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>.

  class NamedLink < Obj

    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 #:nodoc:
      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.
    def self.find_named_link_obj
      Obj.find_by_path("/_named_links")
    end

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

    def self.cache_expired? #:nodoc:
      true
    end

    # Returns the CMS object mapped to the given title or nil.
    # The title can be a string of symbol.
    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 #:nodoc:
      @@named_links_cache = nil
    end

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

    def self.named_links_cache #:nodoc:
      @@named_links_cache
    end

  end

end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
infopark_cloud_connector-6.8.0.beta.200.621.4c8e1b0 lib/rails_connector/named_link.rb