Class: StubRequests::URI::Builder
- Defined in:
- lib/stub_requests/uri/builder.rb
Overview
Builder constructs and validates URIs
Constant Summary collapse
- URI_KEY =
Returns A pattern for matching url segment keys
/(:[a-zA-Z_]+)/.freeze
Instance Attribute Summary collapse
- #expected_keys ⇒ Object readonly
- #received_keys ⇒ Object readonly
- #route_params ⇒ Object readonly
- #uri ⇒ Object readonly
Class Method Summary collapse
-
.build(uri, route_params = {}) ⇒ String
Convenience method to avoid .new.build.
Instance Method Summary collapse
-
#build ⇒ String
Builds a URI string.
-
#initialize(uri, route_params = {}) ⇒ Builder
constructor
Initializes a new Builder.
Constructor Details
#initialize(uri, route_params = {}) ⇒ Builder
Initializes a new Builder
66 67 68 69 70 71 |
# File 'lib/stub_requests/uri/builder.rb', line 66 def initialize(uri, route_params = {}) @uri = +uri @route_params = route_params.to_route_param @received_keys = @route_params.keys @expected_keys = uri.scan(URI_KEY).flatten.uniq end |
Instance Attribute Details
#expected_keys ⇒ Object (readonly)
57 58 59 |
# File 'lib/stub_requests/uri/builder.rb', line 57 def expected_keys @expected_keys end |
#received_keys ⇒ Object (readonly)
53 54 55 |
# File 'lib/stub_requests/uri/builder.rb', line 53 def received_keys @received_keys end |
#route_params ⇒ Object (readonly)
49 50 51 |
# File 'lib/stub_requests/uri/builder.rb', line 49 def route_params @route_params end |
#uri ⇒ Object (readonly)
45 46 47 |
# File 'lib/stub_requests/uri/builder.rb', line 45 def uri @uri end |
Class Method Details
.build(uri, route_params = {}) ⇒ String
Convenience method to avoid .new.build
38 39 40 |
# File 'lib/stub_requests/uri/builder.rb', line 38 def self.build(uri, route_params = {}) new(uri, route_params).build end |
Instance Method Details
#build ⇒ String
Builds a URI string
82 83 84 85 86 87 88 |
# File 'lib/stub_requests/uri/builder.rb', line 82 def build validate_uri_has_route_params! build_uri validate_uri uri end |