Class: AndSon::StoredResponses::Stub

Inherits:
Object
  • Object
show all
Defined in:
lib/and-son/stored_responses.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStub



32
33
34
35
# File 'lib/and-son/stored_responses.rb', line 32

def initialize
  @default_proc = proc{ |r| r.data = Hash.new }
  @hash = {}
end

Instance Attribute Details

#hashObject (readonly)

Returns the value of attribute hash.



30
31
32
# File 'lib/and-son/stored_responses.rb', line 30

def hash
  @hash
end

Instance Method Details

#call(params) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/and-son/stored_responses.rb', line 46

def call(params)
  block = @hash[params] || @default_proc
  if block.arity == 0 || block.arity == -1
    default_response.tap{ |r| r.data = block.call }
  else
    default_response.tap{ |r| block.call(r) }
  end
end

#set_default_proc(&block) ⇒ Object



37
38
39
# File 'lib/and-son/stored_responses.rb', line 37

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

#with(params, &block) ⇒ Object



41
42
43
44
# File 'lib/and-son/stored_responses.rb', line 41

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