class Caracal::Core::Models::RelationshipModel

This class encapsulates the logic needed to store and manipulate relationship data.

Constants

TYPE_MAP

constants

Attributes

relationship_data[R]
relationship_id[R]

accessors

relationship_key[R]
relationship_target[R]
relationship_type[R]

Public Instance Methods

data(value) click to toggle source
# File lib/caracal/core/models/relationship_model.rb, line 78
def data(value)
  @relationship_data = value.to_s
end
formatted_id() click to toggle source
GETTERS =============================
# File lib/caracal/core/models/relationship_model.rb, line 44
def formatted_id
  "rId#{ relationship_id }"
end
formatted_target() click to toggle source
# File lib/caracal/core/models/relationship_model.rb, line 48
def formatted_target
  if relationship_type == :image
    ext = relationship_target.to_s.split('.').last
    ext = ext.split('?').first
    "media/image#{ relationship_id }.#{ ext }"
  else
    relationship_target
  end
end
formatted_type() click to toggle source
# File lib/caracal/core/models/relationship_model.rb, line 58
def formatted_type
  TYPE_MAP.fetch(relationship_type)
end
id(value) click to toggle source
SETTERS =============================
# File lib/caracal/core/models/relationship_model.rb, line 65
def id(value)
  @relationship_id = value.to_i
end
matches?(str) click to toggle source
STATE ===============================
# File lib/caracal/core/models/relationship_model.rb, line 85
def matches?(str)
  relationship_key.downcase == str.to_s.downcase
end
target(value) click to toggle source
# File lib/caracal/core/models/relationship_model.rb, line 73
def target(value)
  @relationship_target = value.to_s
  @relationship_key    = value.to_s.downcase
end
target_mode?() click to toggle source
# File lib/caracal/core/models/relationship_model.rb, line 89
def target_mode?
  relationship_type == :link
end
type(value) click to toggle source
# File lib/caracal/core/models/relationship_model.rb, line 69
def type(value)
  @relationship_type = value.to_s.downcase.to_sym
end
valid?() click to toggle source
VALIDATION ===========================
# File lib/caracal/core/models/relationship_model.rb, line 96
def valid?
  required = [:id, :target, :type]
  required.all? { |m| !send("relationship_#{ m }").nil? }
end

Private Instance Methods

option_keys() click to toggle source
# File lib/caracal/core/models/relationship_model.rb, line 107
def option_keys
  [:id, :type, :target, :data]
end