Sha256: 63146ec1ae9d7f001afae3d5594b02971ba86314835540965f3e8a9af25275ea

Contents?: true

Size: 1.39 KB

Versions: 1

Compression:

Stored size: 1.39 KB

Contents

# encoding: UTF-8

require 'aasm'

module Rosette
  module Core

    # Provides a state machine for transitioning between the possible states of
    # a commit log.
    module CommitLogStatus
      # aasm requires all states to be symbols
      Rosette::DataStores::PhraseStatus.all.each do |status|
        self.const_set(status, status.to_sym)
      end

      def self.included(base)
        base.class_eval do
          include AASM

          aasm do
            # define states from PhraseStatus constants
            Rosette::DataStores::PhraseStatus.all.each do |status|
              state status.to_sym
            end

            attribute_name :status
            initial_state NOT_SEEN

            event :fetch do
              transitions from: NOT_SEEN, to: FETCHED
            end

            event :extract do
              transitions from: FETCHED, to: EXTRACTED
            end

            event :push do
              transitions from: [EXTRACTED, PUSHED], to: PUSHED
            end

            event :finalize do
              transitions from: [EXTRACTED, PUSHED, FINALIZED], to: FINALIZED
            end

            # called when jgit can't find the commit
            event :missing do
              transitions(
                from: Rosette::DataStores::PhraseStatus.statuses,
                to: MISSING
              )
            end
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rosette-core-1.0.1 lib/rosette/core/extractor/commit_log_status.rb