Sha256: b1abf0301df4b5de40c8ddb1a6bc97cd7245e0c9274125b83d0df6236717b96e

Contents?: true

Size: 1.38 KB

Versions: 5

Compression:

Stored size: 1.38 KB

Contents

# -*- coding: utf-8 -*-
require 'tengine/job'

require 'tengine_resource'

module Tengine::Job::Connectable
  extend ActiveSupport::Concern

  included do
    field :server_name    , :type => String # 接続先となるサーバ名。Tengine::Resource::Server#name を指定します
    field :credential_name, :type => String # 接続時に必要な認証情報。Tengine::Resource::Credential#name を指定します

    include Tengine::Job::MmCompatibility::Connectable

    def actual_credential_name
      credential_name || (parent ? parent.actual_credential_name : nil)
    end

    def actual_server_name
      server_name || (parent ? parent.actual_server_name : nil)
    end

    def actual_credential
      key = actual_credential_name
      return nil if key.blank?
      result = Tengine::Resource::Credential.first(:conditions => {:name => key})
      # TODO 使用する例外クラスはこれで良いのか検討
      raise Mongoid::Errors::DocumentNotFound.new(Tengine::Resource::Credential, key) unless result
      result
    end

    def actual_server
      key = actual_server_name
      return nil if key.blank?
      result = Tengine::Resource::Server.first(:conditions => {:name => key})
      # TODO 使用する例外クラスはこれで良いのか検討
      raise Mongoid::Errors::DocumentNotFound.new(Tengine::Resource::Server, key) unless result
      result
    end


  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
tengine_job-0.6.13 lib/tengine/job/connectable.rb
tengine_job-0.6.12 lib/tengine/job/connectable.rb
tengine_job-0.6.11 lib/tengine/job/connectable.rb
tengine_job-0.6.10 lib/tengine/job/connectable.rb
tengine_job-0.6.9 lib/tengine/job/connectable.rb