Class: Scmd::StoredCommands::Stub

Inherits:
Object
  • Object
show all
Defined in:
lib/scmd/stored_commands.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cmd_str) ⇒ Stub

Returns a new instance of Stub.



44
45
46
47
48
# File 'lib/scmd/stored_commands.rb', line 44

def initialize(cmd_str)
  @cmd_str = cmd_str
  @default_proc = proc{ |cmd_spy| } # no-op
  @hash = {}
end

Instance Attribute Details

#cmd_strObject (readonly)

Returns the value of attribute cmd_str.



42
43
44
# File 'lib/scmd/stored_commands.rb', line 42

def cmd_str
  @cmd_str
end

#hashObject (readonly)

Returns the value of attribute hash.



42
43
44
# File 'lib/scmd/stored_commands.rb', line 42

def hash
  @hash
end

Instance Method Details

#==(other) ⇒ Object



64
65
66
67
68
69
70
71
# File 'lib/scmd/stored_commands.rb', line 64

def ==(other)
  if other.is_a?(Stub)
    cmd_str == other.cmd_str &&
    hash    == other.hash
  else
    super
  end
end

#call(opts) ⇒ Object



59
60
61
62
# File 'lib/scmd/stored_commands.rb', line 59

def call(opts)
  block = @hash[opts] || @default_proc
  CommandSpy.new(@cmd_str, opts).tap(&block)
end

#set_default_proc(&block) ⇒ Object



50
51
52
# File 'lib/scmd/stored_commands.rb', line 50

def set_default_proc(&block)
  @default_proc = block if block
end

#with(opts, &block) ⇒ Object



54
55
56
57
# File 'lib/scmd/stored_commands.rb', line 54

def with(opts, &block)
  @hash[opts] = block
  self
end