Class: ProtoPharm::RequestPattern
- Inherits:
-
Object
- Object
- ProtoPharm::RequestPattern
- Defined in:
- lib/proto_pharm/request_pattern.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Instance Method Summary collapse
-
#initialize(path) ⇒ RequestPattern
constructor
A new instance of RequestPattern.
- #match?(match_path, match_request) ⇒ Boolean
- #with(request = nil, &block) ⇒ Object
Constructor Details
#initialize(path) ⇒ RequestPattern
Returns a new instance of RequestPattern.
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
#block ⇒ Object (readonly)
Returns the value of attribute block.
5 6 7 |
# File 'lib/proto_pharm/request_pattern.rb', line 5 def block @block end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/proto_pharm/request_pattern.rb', line 5 def path @path end |
#request ⇒ Object (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
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 |