Class: ProtoPharm::RequestPattern

Inherits:
Object
  • Object
show all
Defined in:
lib/proto_pharm/request_pattern.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ RequestPattern

Returns a new instance of RequestPattern.

Parameters:

  • path (String)


8
9
10
11
12
# File 'lib/proto_pharm/request_pattern.rb', line 8

def initialize(path)
  @path = path
  @block = nil
  @request = nil
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



5
6
7
# File 'lib/proto_pharm/request_pattern.rb', line 5

def block
  @block
end

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/proto_pharm/request_pattern.rb', line 5

def path
  @path
end

#requestObject (readonly)

Returns the value of attribute request.



5
6
7
# File 'lib/proto_pharm/request_pattern.rb', line 5

def request
  @request
end

Instance Method Details

#match?(match_path, match_request) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
# File 'lib/proto_pharm/request_pattern.rb', line 23

def match?(match_path, match_request)
  path == match_path &&
    (request.nil? || request == match_request) &&
    (block.nil? || block.call(match_path))
end

#with(request = nil, &block) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/proto_pharm/request_pattern.rb', line 14

def with(request = nil, &block)
  if request.nil? && !block_given?
    raise ArgumentError, "#with method invoked with no arguments. Either options request or block must be specified."
  end

  @request = request
  @block = block
end