Sha256: 2ff250f7745027fad0ef97bec29386af88e259b8141fb1253c4426cfe9042ce1

Contents?: true

Size: 1003 Bytes

Versions: 7

Compression:

Stored size: 1003 Bytes

Contents

module Rundock
  module Operation
    class Base
      OperationNotImplementedError = Class.new(NotImplementedError)

      attr_reader :instruction
      attr_reader :attributes

      def initialize(instruction, attributes)
        @instruction = instruction
        @attributes = attributes
        @attributes = {} unless attributes
      end

      def run(backend, attributes = {})
        raise OperationNotImplementedError
      end

      def logging(message, severity)
        h_host = @attributes[:nodename].just(' ', 15)
        h_ope = "start #{self.class.to_s.split('::').last.downcase}:"
        Logger.send(severity.to_sym, "#{h_host} #{h_ope} #{message}")
      end

      def assign_args(src, args)
        return src unless args
        src.gsub(/\$#/, args.length.to_s)
           .gsub(/\$@/, args.join(' '))
           .gsub(/\$[1-9]/) { |arg_n| args[arg_n.chars[1..-1].join.to_i - 1] }
           .gsub(/(\$\{)(\w+)(\})/) { ENV[Regexp.last_match(2)] }
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rundock-1.2.0 lib/rundock/operation/base.rb
rundock-1.1.7 lib/rundock/operation/base.rb
rundock-1.1.6 lib/rundock/operation/base.rb
rundock-1.1.5 lib/rundock/operation/base.rb
rundock-1.1.4 lib/rundock/operation/base.rb
rundock-1.1.3 lib/rundock/operation/base.rb
rundock-1.1.2 lib/rundock/operation/base.rb