Class: Scmd::StoredCommands::Stub
- Inherits:
-
Object
- Object
- Scmd::StoredCommands::Stub
- Defined in:
- lib/scmd/stored_commands.rb
Instance Attribute Summary collapse
-
#cmd_str ⇒ Object
readonly
Returns the value of attribute cmd_str.
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
Instance Method Summary collapse
- #==(other_stub) ⇒ Object
- #call(opts) ⇒ Object
-
#initialize(cmd_str) ⇒ Stub
constructor
A new instance of Stub.
- #set_default_proc(&block) ⇒ Object
- #with(opts, &block) ⇒ Object
Constructor Details
#initialize(cmd_str) ⇒ Stub
Returns a new instance of Stub.
45 46 47 48 49 |
# File 'lib/scmd/stored_commands.rb', line 45 def initialize(cmd_str) @cmd_str = cmd_str @default_proc = proc{ |cmd_spy| } # no-op @hash = {} end |
Instance Attribute Details
#cmd_str ⇒ Object (readonly)
Returns the value of attribute cmd_str.
43 44 45 |
# File 'lib/scmd/stored_commands.rb', line 43 def cmd_str @cmd_str end |
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
43 44 45 |
# File 'lib/scmd/stored_commands.rb', line 43 def hash @hash end |
Instance Method Details
#==(other_stub) ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/scmd/stored_commands.rb', line 65 def ==(other_stub) if other_stub.kind_of?(Stub) self.cmd_str == other_stub.cmd_str && self.hash == other_stub.hash else super end end |
#call(opts) ⇒ Object
60 61 62 63 |
# File 'lib/scmd/stored_commands.rb', line 60 def call(opts) block = @hash[opts] || @default_proc CommandSpy.new(@cmd_str, opts).tap(&block) end |
#set_default_proc(&block) ⇒ Object
51 52 53 |
# File 'lib/scmd/stored_commands.rb', line 51 def set_default_proc(&block) @default_proc = block if block end |
#with(opts, &block) ⇒ Object
55 56 57 58 |
# File 'lib/scmd/stored_commands.rb', line 55 def with(opts, &block) @hash[opts] = block self end |