Sha256: 6a89326f59420d03168ac0209d0bac9bdb1bfb0fa1db406be05a357b744c62af

Contents?: true

Size: 1.31 KB

Versions: 2

Compression:

Stored size: 1.31 KB

Contents

module GitCompound
  module Command
    module Procedure
      # Abstract Procedure class
      #
      class Procedure
        def initialize(_opts)
        end

        # Method with additional messages etc.
        #
        def execute!
          execute
        end

        # Main procedure entry point
        #
        def execute
          self.class.steps.to_h.keys.each do |name|
            execute_step(name)
          end
        end

        def execute_step(name)
          step_proc = self.class.steps.to_h[name]
          instance_eval(&step_proc) if step_proc
        end

        class << self
          attr_reader :steps

          # Valid options available for this procedure
          # see Element::Option
          #
          def options
            {}
          end

          # Name of procedure
          #
          def to_s
            name.split('::').last
              .gsub(/::/, '/')
              .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
              .gsub(/([a-z\d])([A-Z])/, '\1_\2')
              .tr('-', '_')
              .downcase
          end

          private

          def step(name, &block)
            raise GitCompoundError, 'No block given !' unless block

            @steps = {} unless @steps
            @steps.store(name, block)
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
git_compound-0.2.2 lib/git_compound/command/procedure/procedure.rb
git_compound-0.2.1 lib/git_compound/command/procedure/procedure.rb