Sha256: 22d4bc0f9ad3947b5bc5b8d3f00e7e62002789756a7ddbad9e6a8478c0c929fc

Contents?: true

Size: 834 Bytes

Versions: 1

Compression:

Stored size: 834 Bytes

Contents

module Omnitest
  class Psychic
    class CommandTemplate
      attr_reader :psychic

      def initialize(psychic, template)
        @psychic = psychic
        fail ArgumentError, 'Cannot create a nil command' if template.nil?
        @template = template
      end

      def command(params = {})
        Tokens.replace_tokens(build_command, params)
      end

      def execute(params = {}, *args)
        shell_opts = args.shift if args.first.is_a? Hash
        shell_opts ||= {}
        @psychic.execute(command(params), shell_opts, *args)
      end

      alias_method :to_s, :command

      private

      def build_command
        @command ||= if @template.respond_to?(:call)
                       @template.call
                     else
                       @template
                     end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
omnitest-psychic-0.0.9 lib/omnitest/psychic/command_template.rb