Sha256: 10c62e09d3109fd899dee45ca7600ec3ba1f3e8040f32970e8ff664e7fadf94a

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 KB

Contents

require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/hash/except'

class Job
  module States
    def propagate(*args)
      owner.send(*args)
      true
    end

    def update_attributes(attributes)
      if content = attributes.delete(:log)
        log.update_attributes(:content => content)
      end
      update_states(attributes.deep_symbolize_keys)
      super
    end

    def passed?
      status == 0
    end

    def failed?
      status == 1
    end

    def unknown?
      status == nil
    end

    protected

      # extracts attributes like :started_at, :finished_at, :config from the given attributes and triggers
      # state changes based on them. See the respective `extract_[state]ing_attributes` methods.
      def update_states(attributes)
        [:start, :finish].each do |state|
          state_attributes = send(:"extract_#{state}ing_attributes", attributes)
          send(:"#{state}!", state_attributes) if state_attributes.present?
        end
      end

      def extract_starting_attributes(attributes)
        extract!(attributes, :started_at)
      end

      def extract!(hash, *keys)
        # arrrgh. is there no ruby or activesupport hash method that does this?
        hash.slice(*keys).tap { |result| hash.except!(*keys) }
      rescue KeyError
        {}
      end
  end
end


Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
travis-core-0.0.1 lib/travis/model/job/states.rb