class Reactor::Cm::Link

Attributes

dest_obj_id[R]
dest_url[R]
position[RW]
target[RW]
title[RW]

Public Class Methods

create(content, attr, url, title=nil) click to toggle source
# File lib/reactor/cm/link.rb, line 23
def self.create(content, attr, url, title=nil)
  link = Link.new
  link.send(:create, content, attr, url, title)
  link
end
create_inside(obj, attr, url, title=nil) click to toggle source
# File lib/reactor/cm/link.rb, line 19
def self.create_inside(obj, attr, url, title=nil)
  create(obj.edited_content, attr, url, title)
end
exists?(id) click to toggle source
# File lib/reactor/cm/link.rb, line 7
def self.exists?(id)
  return !Link.get(id).nil?
rescue XmlRequestError => e
  return false
end
get(id) click to toggle source
# File lib/reactor/cm/link.rb, line 13
def self.get(id)
  link = Link.new
  link.send(:get,id)
  link
end
new() click to toggle source
# File lib/reactor/cm/link.rb, line 82
def initialize
end

Public Instance Methods

delete!() click to toggle source
# File lib/reactor/cm/link.rb, line 73
def delete!
  request = XmlRequest.prepare do |xml|
    xml.where_key_tag!(base_name, 'id', @link_id)
    xml.tag!("#{base_name}-delete")
  end
  response = request.execute!
end
dest_obj_id=(obj_id) click to toggle source
# File lib/reactor/cm/link.rb, line 37
def dest_obj_id=(obj_id)
  @is_external  = false
  @dest_url     = Obj.get(obj_id).path
  @dest_obj_id  = obj_id
end
dest_url=(url) click to toggle source
# File lib/reactor/cm/link.rb, line 43
def dest_url=(url)
  @is_external  = (/^\// =~ url).nil?
  @dest_obj_id  = Obj.get(url).obj_id unless @is_external
  @dest_url     = url
end
eql?(other) click to toggle source
# File lib/reactor/cm/link.rb, line 69
def eql?(other)
  self.link_id == other.link_id
end
hash() click to toggle source
# File lib/reactor/cm/link.rb, line 62
def hash
  # yes, to_s.to_is is neccesary,
  # because self.link_id is of type REXML::Text for the most of the time
  self.link_id.to_s.to_i
end
is_external?() click to toggle source
# File lib/reactor/cm/link.rb, line 29
def is_external?
  @is_external == true
end
is_internal?() click to toggle source
# File lib/reactor/cm/link.rb, line 33
def is_internal?
  !is_external?
end
save!() click to toggle source
# File lib/reactor/cm/link.rb, line 49
def save!
  request = XmlRequest.prepare do |xml|
    xml.where_key_tag!(base_name, 'id', @link_id)
    xml.set_tag!(base_name) do
      xml.tag!('target', @target) if @target
      xml.tag!('title', @title) if @title
      xml.tag!('destinationUrl', @dest_url) if @dest_url
      xml.tag!('position', @position) if @position
    end
  end
  response = request.execute!
end

Protected Instance Methods

base_name() click to toggle source
# File lib/reactor/cm/link.rb, line 85
def base_name
  'link'
end
create(content, attr, url, title = nil) click to toggle source
# File lib/reactor/cm/link.rb, line 107
def create(content, attr, url, title = nil)
  request = XmlRequest.prepare do |xml|
    xml.create_tag!(base_name) do
      xml.tag!('attributeName', attr.to_s)
      xml.tag!('sourceContent', content.to_s)
      xml.tag!('destinationUrl', url.to_s)
    end
  end
  response = request.execute!

  id = response.xpath('//id/text()')
  get(id)

  if !title.nil?
    request = XmlRequest.prepare do |xml|
      xml.where_key_tag!(base_name, 'id', id)
      xml.set_key_tag!(base_name, 'title', title)
    end
    response = request.execute!
  end

  self
end
get(id) click to toggle source
# File lib/reactor/cm/link.rb, line 89
def get(id)
  request = XmlRequest.prepare do |xml|
    xml.where_key_tag!(base_name, 'id', id)
    xml.get_key_tag!(base_name, ['id', 'isExternalLink', 'target', 'title', 'destination', 'destinationUrl', 'position'])
  end
  response      = request.execute!

  @link_id      = response.xpath('//id/text()')
  @is_external  = response.xpath('//isExternalLink/text()') == '1'
  @target       = response.xpath('//target/text()').presence
  @title        = response.xpath('//title/text()').presence
  @dest_obj_id  = response.xpath('//destination/text()').presence
  @dest_url     = response.xpath('//destinationUrl/text()').presence
  @position     = response.xpath('//position/text()').presence

  self
end