Sha256: f1e088a75b1e9b064c1f7fa81eff18152a7d26860ed8365d44cd974f62105810

Contents?: true

Size: 1.35 KB

Versions: 14

Compression:

Stored size: 1.35 KB

Contents

module Kaya
  module Custom
    class ExecutionData

      # This class is used from execution code. It means that user can call this method to store information
      # during exdecution.

      # Returns execution id
      def self.id
        ENV["_id"]
      end

      def self.is_there_result?
        Kaya::Database::MongoConnector.result_data_for_id(self.id)
      end

      # Stores a key => value pair to the result
      # @param [String or Symbol] key
      # @param [Any] value
      # @return hash if stored, nil if not
      def self.add key=nil, value=nil
        self.ensure_db_connection
        if self.is_there_result?
          result = self.get_result
          if result and result.running?
            result.add_execution_data key, value if key
            {key => value}
          end
        end
      end

      def self.get_result
        Kaya::Results::Result.get(self.id)
      end

      # Returns result execution data if exist. Else returns an empty hash
      def self.get_data
        self.is_there_result? ? self.get_result.execution_data : {}
      end

      # Conntects to database if not connected
      def self.ensure_db_connection
        Kaya::Support::Configuration.get
        Kaya::Database::MongoConnector.new(Kaya::Support::Configuration.db_connection_data) unless Kaya::Database::MongoConnector.connected?
      end


    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
kaya-0.0.14 lib/kaya/custom/execution_data.rb
kaya-0.0.13 lib/kaya/custom/execution_data.rb
kaya-0.0.12 lib/kaya/custom/execution_data.rb
kaya-0.0.11 lib/kaya/custom/execution_data.rb
kaya-0.0.10 lib/kaya/custom/execution_data.rb
kaya-0.0.9 lib/kaya/custom/execution_data.rb
kaya-0.0.8 lib/kaya/custom/execution_data.rb
kaya-0.0.7 lib/kaya/custom/execution_data.rb
kaya-0.0.6 lib/kaya/custom/execution_data.rb
kaya-0.0.5 lib/kaya/custom/execution_data.rb
kaya-0.0.4 lib/kaya/custom/execution_data.rb
kaya-0.0.3 lib/kaya/custom/execution_data.rb
kaya-0.0.2 lib/kaya/custom/execution_data.rb
kaya-0.0.1 lib/kaya/custom/execution_data.rb