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.210.ed204b0 lib/rails_connector/named_link.rb
infopark_cloud_connector-6.8.0.110.6570b45 lib/rails_connector/named_link.rb
infopark_cloud_connector-6.8.0.72.d18d096 lib/rails_connector/named_link.rb
infopark_cloud_connector-6.8.0.23.da7f96b lib/rails_connector/named_link.rb
infopark_cloud_connector-6.8.0.16.def5e85 lib/rails_connector/named_link.rb
infopark_cloud_connector-6.8.0.15.a24f5ff lib/rails_connector/named_link.rb
infopark_cloud_connector-6.8.0.beta.200.891.647580e lib/rails_connector/named_link.rb
infopark_cloud_connector-6.8.0.beta.200.889.d503e42 lib/rails_connector/named_link.rb
infopark_cloud_connector-6.8.0.beta.200.883.f5f063b lib/rails_connector/named_link.rb
infopark_cloud_connector-6.8.0.beta.200.884.4bd86e6 lib/rails_connector/named_link.rb
infopark_cloud_connector-6.8.0.beta.200.869.9609b39 lib/rails_connector/named_link.rb
infopark_cloud_connector-6.8.0.beta.200.856.8c0fec5 lib/rails_connector/named_link.rb
infopark_cloud_connector-6.8.0.beta.200.809.bdfa8c3 lib/rails_connector/named_link.rb
infopark_cloud_connector-6.8.0.beta.200.785.05d4af9 lib/rails_connector/named_link.rb
infopark_cloud_connector-6.8.0.beta.200.744.99f67fc lib/rails_connector/named_link.rb
infopark_cloud_connector-6.8.0.beta.200.720.44fbabd lib/rails_connector/named_link.rb
infopark_cloud_connector-6.8.0.beta.200.713.e5c3150 lib/rails_connector/named_link.rb
infopark_cloud_connector-6.8.0.beta.200.681.7c84f4a lib/rails_connector/named_link.rb
infopark_cloud_connector-6.8.0.beta.200.663.ceecdee lib/rails_connector/named_link.rb
infopark_cloud_connector-6.8.0.beta.200.650.7c93155 lib/rails_connector/named_link.rb