Class: ROM::HTTP::Dataset
- Inherits:
-
Object
- Object
- ROM::HTTP::Dataset
- Extended by:
- Initializer
- Includes:
- Enumerable
- Defined in:
- lib/rom/http/dataset.rb
Overview
HTTP Dataset
Represents a specific HTTP collection resource
Constant Summary collapse
- PATH_SEPARATOR =
'/'.freeze
- STRIP_PATH =
->(path) { path.sub(%r{\A/}, '') }.freeze
Class Method Summary collapse
- .default_request_handler(handler = Undefined) ⇒ Object
- .default_response_handler(handler = Undefined) ⇒ Object
Instance Method Summary collapse
-
#absolute_path ⇒ string
Return the dataset path.
-
#add_header(header, value) ⇒ Dataset
Return a new dataset with additional header.
-
#append_path(append_path) ⇒ Dataset
Return a new dataset with a modified path.
-
#base_path ⇒ String
Return the base path.
-
#delete ⇒ Array<Hash>
Perform an delete over HTTP Delete.
-
#each {|Hash| ... } ⇒ Enumerator, Array<Hash>
Iterate over each response value.
-
#headers ⇒ Hash
Return request headers.
-
#insert(params) ⇒ Array<Hash>
Perform an insert over HTTP Post.
-
#name ⇒ String
Return the dataset name.
-
#path ⇒ String
Return the dataset path.
-
#response ⇒ Array<hash>
Execute the current dataset.
-
#update(params) ⇒ Array<Hash>
Perform an update over HTTP Put.
-
#uri ⇒ String
Return the gateway’s URI.
-
#with_base_path(base_path) ⇒ Dataset
Return a new dataset with a different base path.
-
#with_headers(headers) ⇒ Dataset
Return a new dataset with given headers.
-
#with_options(opts) ⇒ Dataset
Return a new dataset with additional options.
-
#with_params(params) ⇒ Dataset
Return a new dataset with replaced request parameters.
-
#with_path(path) ⇒ Dataset
Return a new dataset with a different path.
-
#with_request_method(request_method) ⇒ Dataset
Return a new dataset with a different request method.
Class Method Details
.default_request_handler(handler = Undefined) ⇒ Object
27 28 29 30 |
# File 'lib/rom/http/dataset.rb', line 27 def default_request_handler(handler = Undefined) return @default_request_handler if Undefined === handler @default_request_handler = handler end |
.default_response_handler(handler = Undefined) ⇒ Object
32 33 34 35 |
# File 'lib/rom/http/dataset.rb', line 32 def default_response_handler(handler = Undefined) return @default_response_handler if Undefined === handler @default_response_handler = handler end |
Instance Method Details
#absolute_path ⇒ string
Return the dataset path
111 112 113 |
# File 'lib/rom/http/dataset.rb', line 111 def absolute_path PATH_SEPARATOR + path end |
#add_header(header, value) ⇒ Dataset
Return a new dataset with additional header
147 148 149 |
# File 'lib/rom/http/dataset.rb', line 147 def add_header(header, value) with_headers(headers.merge(header => value)) end |
#append_path(append_path) ⇒ Dataset
Return a new dataset with a modified path
203 204 205 |
# File 'lib/rom/http/dataset.rb', line 203 def append_path(append_path) (path: join_path(path, append_path)) end |
#base_path ⇒ String
Return the base path
85 86 87 |
# File 'lib/rom/http/dataset.rb', line 85 def base_path STRIP_PATH.call(super) end |
#delete ⇒ Array<Hash>
Perform an delete over HTTP Delete
284 285 286 287 288 |
# File 'lib/rom/http/dataset.rb', line 284 def delete ( request_method: :delete ).response end |
#each {|Hash| ... } ⇒ Enumerator, Array<Hash>
Iterate over each response value
245 246 247 248 |
# File 'lib/rom/http/dataset.rb', line 245 def each(&block) return to_enum unless block_given? response.each(&block) end |
#headers ⇒ Hash
Return request headers
Merges default headers from the Gateway configuration and the current Dataset
63 64 65 |
# File 'lib/rom/http/dataset.rb', line 63 def headers config.fetch(:headers, {}).merge(.fetch(:headers, {})) end |
#insert(params) ⇒ Array<Hash>
Perform an insert over HTTP Post
257 258 259 260 261 262 |
# File 'lib/rom/http/dataset.rb', line 257 def insert(params) ( request_method: :post, params: params ).response end |
#name ⇒ String
Return the dataset name
72 73 74 |
# File 'lib/rom/http/dataset.rb', line 72 def name config[:name].to_s end |
#path ⇒ String
Return the dataset path
98 99 100 |
# File 'lib/rom/http/dataset.rb', line 98 def path STRIP_PATH.call(join_path(base_path, super)) end |
#response ⇒ Array<hash>
Execute the current dataset
295 296 297 |
# File 'lib/rom/http/dataset.rb', line 295 def response response_handler.call(request_handler.call(self), self) end |
#update(params) ⇒ Array<Hash>
Perform an update over HTTP Put
271 272 273 274 275 276 |
# File 'lib/rom/http/dataset.rb', line 271 def update(params) ( request_method: :put, params: params ).response end |
#uri ⇒ String
Return the gateway’s URI
45 46 47 |
# File 'lib/rom/http/dataset.rb', line 45 def uri config.fetch(:uri) { fail Error, ':uri configuration missing' } end |
#with_base_path(base_path) ⇒ Dataset
Return a new dataset with a different base path
173 174 175 |
# File 'lib/rom/http/dataset.rb', line 173 def with_base_path(base_path) (base_path: base_path) end |
#with_headers(headers) ⇒ Dataset
this replaces the dataset’s currently configured headers. To non-destructively add a new header, use #add_header
Return a new dataset with given headers
130 131 132 |
# File 'lib/rom/http/dataset.rb', line 130 def with_headers(headers) __new__(config, .merge(headers: headers)) end |
#with_options(opts) ⇒ Dataset
Return a new dataset with additional options
158 159 160 |
# File 'lib/rom/http/dataset.rb', line 158 def (opts) __new__(config, .merge(opts)) end |
#with_params(params) ⇒ Dataset
Return a new dataset with replaced request parameters
233 234 235 |
# File 'lib/rom/http/dataset.rb', line 233 def with_params(params) (params: params) end |
#with_path(path) ⇒ Dataset
Return a new dataset with a different path
188 189 190 |
# File 'lib/rom/http/dataset.rb', line 188 def with_path(path) (path: path) end |
#with_request_method(request_method) ⇒ Dataset
Return a new dataset with a different request method
217 218 219 |
# File 'lib/rom/http/dataset.rb', line 217 def with_request_method(request_method) (request_method: request_method) end |