Sha256: 9120129c70bfe9ce71de262ccd6979b7fd4742954a1f00b2235f9e437b31353e

Contents?: true

Size: 1.81 KB

Versions: 36

Compression:

Stored size: 1.81 KB

Contents

module ShInterceptor

  # for sh, and system with arguments turned into a string
  attr_accessor :received

  # for #system
  attr_accessor :executable

  # for #system
  attr_accessor :parameters

  # for #system
  attr_accessor :options

  def is_mono_command? index = 0
    e = invocations[index].executable
    e.downcase == 'mono'
  end

  # gets the command (which might be mono-prefixed), without
  # the mono-prefix.
  def mono_command index = 0
    invocation = invocations[index]
    fail "no invocation with index = #{index}" unless invocation
    parameters = invocation.parameters
    is_mono_command?(index) ?
      parameters[0] :
      executable
  end

  def mono_parameters index = 0
    invocation = invocations[index]
    fail "no invocation with index = #{index}" unless invocation
    parameters = invocation.parameters
    is_mono_command?(index) ?
      parameters[1..-1] :
      parameters
  end

  def system_calls
    if @system_calls.nil?
      0
    else
      @system_calls
    end
  end

  # intercepts #system
  def system *args
    @options = (Hash === args.last) ? args.pop : {}
    @executable = args[0] || ''
    @parameters = args[1..-1].flatten || []
    @system_calls = system_calls + 1
    add_invocation(OpenStruct.new({ :executable => @executable, :parameters => @parameters, :options => @options}))
  end

  # gets the invocations given to #system, with readers:
  # + executable : string
  # + parameters : 'a array
  # + options    : Hash
  def invocations
    @invocations || []
  end

  private
  def add_invocation invocation
    Albacore.application.logger.debug "adding invocation: #{invocation}"
    @invocations = (@invocations || [])
    @invocations << invocation
  end

  # intercepts #sh
  def sh *args
    @received = args
  end

  # intercepts #shie
  def shie *args
    @received = args
  end

end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
albacore-2.0.15 spec/support/sh_interceptor.rb
albacore-2.0.14 spec/support/sh_interceptor.rb
albacore-2.0.13 spec/support/sh_interceptor.rb
albacore-2.0.12 spec/support/sh_interceptor.rb
albacore-2.0.11 spec/support/sh_interceptor.rb
albacore-2.0.10 spec/support/sh_interceptor.rb
albacore-2.0.9 spec/support/sh_interceptor.rb
albacore-2.0.8 spec/support/sh_interceptor.rb
albacore-2.0.7 spec/support/sh_interceptor.rb
albacore-2.0.6 spec/support/sh_interceptor.rb
albacore-2.0.5 spec/support/sh_interceptor.rb
albacore-2.0.4 spec/support/sh_interceptor.rb
albacore-2.0.3 spec/support/sh_interceptor.rb
albacore-2.0.2 spec/support/sh_interceptor.rb
albacore-2.0.1 spec/support/sh_interceptor.rb
albacore-2.0.0 spec/support/sh_interceptor.rb
albacore-2.0.0.rc.21 spec/support/sh_interceptor.rb
albacore-2.0.0.rc.20 spec/support/sh_interceptor.rb
albacore-2.0.0.rc.19 spec/support/sh_interceptor.rb
albacore-2.0.0.rc.18 spec/support/sh_interceptor.rb