Sha256: 50d0ab1f86c2a955eb9107fd2ffcc443d820cc0a1c08367cfb3906a9d068386e

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

module ActsAsCleoConnection
  module InstanceMethods
    def create_cleo_connection
      Cleo::ConnectionServer.create(self)
    end

    def update_cleo_connection
      Cleo::ConnectionServer.update(self)
    end

    def remove_cleo_connection
      Cleo::ConnectionServer.delete(self)
    end

    def disable_cleo_connection
      Cleo::ConnectionServer.disable(self)
    end

    def to_cleo_connection
      source = self.send("#{cleo_origin}")
      target = self.send("#{cleo_target}")
      type = self.respond_to?("#{cleo_type}") ? self.send("#{cleo_type}") : cleo_type
      return nil if target.blank? || source.blank?

      is_active = self.respond_to?(:active) ? self.active : nil
      str = target.cleo_score + source.cleo_score

      result = Cleo::Xml::Connection.new

      result.source = source.cleo_id
      result.target = target.cleo_id
      result.active = is_active
      result.strength = str
      result.type = type

      return result
    end

    alias :as_connection :to_cleo_connection

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
acts_as_cleo-3.0.2 lib/acts_as_cleo_connection/instance_methods.rb
acts_as_cleo-3.0.1 lib/acts_as_cleo_connection/instance_methods.rb