Sha256: 8a2513a53a9c18dcb04fc1f427c707720067fe4de0f433ce660f7782c86cf40f

Contents?: true

Size: 1.19 KB

Versions: 12

Compression:

Stored size: 1.19 KB

Contents

# -*- encoding : utf-8 -*-
module Reactor
  module Link
    class TemporaryLink
      attr_reader   :url
      attr_accessor :title
      attr_accessor :target

      def external? ; raise TypeError, "This link needs to be persisted to gain any meaningful information" ; end
      def internal? ; false ; end

      def initialize(anything)
        link_data = {}
        
        case anything
        when Hash
          link_data = anything
        when Fixnum
          link_data[:url] = RailsConnector::AbstractObj.find(anything).path
        else
          link_data[:url] = anything
        end

        self.url    = link_data[:url] || link_data[:destination_object]
        self.target = link_data[:target] if link_data.key?(:target)
        self.title  = link_data[:title] if link_data.key?(:title)
      end

      def url=(some_target)
        @url = case some_target
        when RailsConnector::AbstractObj
          @destination_object = some_target
          some_target.path
        else
          some_target
        end
      end

      def destination_object
        @destination_object ||= RailsConnector::AbstractObj.find_by_path(url)
      end

      def id
        nil
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
infopark_reactor-1.18.0 lib/reactor/link/temporary_link.rb
infopark_reactor-1.17.0 lib/reactor/link/temporary_link.rb
infopark_reactor-1.16.0 lib/reactor/link/temporary_link.rb
infopark_reactor-1.15.0.beta1 lib/reactor/link/temporary_link.rb
infopark_reactor-1.14.0.beta2 lib/reactor/link/temporary_link.rb
infopark_reactor-1.14.0.beta1 lib/reactor/link/temporary_link.rb
infopark_reactor-1.13.0 lib/reactor/link/temporary_link.rb
infopark_reactor-1.12.0 lib/reactor/link/temporary_link.rb
infopark_reactor-1.12.0.beta2 lib/reactor/link/temporary_link.rb
infopark_reactor-1.12.0.beta1 lib/reactor/link/temporary_link.rb
infopark_reactor-1.11.0.beta3 lib/reactor/link/temporary_link.rb
infopark_reactor-1.11.0.beta2 lib/reactor/link/temporary_link.rb