Class: ROM::HTTP::Dataset
- Inherits:
-
Object
- Object
- ROM::HTTP::Dataset
- Includes:
- Enumerable, Options
- Defined in:
- lib/rom/http/dataset.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Class Method Summary collapse
- .default_request_handler(handler = Undefined) ⇒ Object
- .default_response_handler(handler = Undefined) ⇒ Object
Instance Method Summary collapse
- #absolute_path ⇒ Object
- #add_header(header, value) ⇒ Object
- #append_path(path) ⇒ Object
- #delete ⇒ Object
- #each(&block) ⇒ Object
- #headers ⇒ Object
-
#initialize(config, options = {}) ⇒ Dataset
constructor
A new instance of Dataset.
- #insert(params) ⇒ Object
- #name ⇒ Object
- #path ⇒ Object
- #response ⇒ Object
- #update(params) ⇒ Object
- #uri ⇒ Object
- #with_headers(headers) ⇒ Object
- #with_options(opts) ⇒ Object
- #with_params(params) ⇒ Object
- #with_path(path) ⇒ Object
- #with_request_method(request_method) ⇒ Object
Constructor Details
#initialize(config, options = {}) ⇒ Dataset
Returns a new instance of Dataset.
27 28 29 30 |
# File 'lib/rom/http/dataset.rb', line 27 def initialize(config, = {}) @config = config super() end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
8 9 10 |
# File 'lib/rom/http/dataset.rb', line 8 def config @config end |
Class Method Details
.default_request_handler(handler = Undefined) ⇒ Object
16 17 18 19 |
# File 'lib/rom/http/dataset.rb', line 16 def default_request_handler(handler = Undefined) return @default_request_handler if Undefined === handler @default_request_handler = handler end |
.default_response_handler(handler = Undefined) ⇒ Object
21 22 23 24 |
# File 'lib/rom/http/dataset.rb', line 21 def default_response_handler(handler = Undefined) return @default_response_handler if Undefined === handler @default_response_handler = handler end |
Instance Method Details
#absolute_path ⇒ Object
48 49 50 |
# File 'lib/rom/http/dataset.rb', line 48 def absolute_path '/' + path end |
#add_header(header, value) ⇒ Object
56 57 58 |
# File 'lib/rom/http/dataset.rb', line 56 def add_header(header, value) with_headers(headers.merge(header => value)) end |
#append_path(path) ⇒ Object
68 69 70 |
# File 'lib/rom/http/dataset.rb', line 68 def append_path(path) (path: [:path] + '/' + path) end |
#delete ⇒ Object
99 100 101 102 103 |
# File 'lib/rom/http/dataset.rb', line 99 def delete ( request_method: :delete ).response end |
#each(&block) ⇒ Object
80 81 82 83 |
# File 'lib/rom/http/dataset.rb', line 80 def each(&block) return to_enum unless block_given? response.each(&block) end |
#headers ⇒ Object
36 37 38 |
# File 'lib/rom/http/dataset.rb', line 36 def headers config.fetch(:headers, {}).merge(.fetch(:headers, {})) end |
#insert(params) ⇒ Object
85 86 87 88 89 90 |
# File 'lib/rom/http/dataset.rb', line 85 def insert(params) ( request_method: :post, params: params ).response end |
#name ⇒ Object
40 41 42 |
# File 'lib/rom/http/dataset.rb', line 40 def name config[:name].to_s end |
#path ⇒ Object
44 45 46 |
# File 'lib/rom/http/dataset.rb', line 44 def path [:path].to_s.sub(%r{\A/}, '') end |
#response ⇒ Object
105 106 107 |
# File 'lib/rom/http/dataset.rb', line 105 def response response_handler.call(request_handler.call(self), self) end |
#update(params) ⇒ Object
92 93 94 95 96 97 |
# File 'lib/rom/http/dataset.rb', line 92 def update(params) ( request_method: :put, params: params ).response end |
#uri ⇒ Object
32 33 34 |
# File 'lib/rom/http/dataset.rb', line 32 def uri config.fetch(:uri) { fail Error, ':uri configuration missing' } end |
#with_headers(headers) ⇒ Object
52 53 54 |
# File 'lib/rom/http/dataset.rb', line 52 def with_headers(headers) __new__(config, .merge(headers: headers)) end |
#with_options(opts) ⇒ Object
60 61 62 |
# File 'lib/rom/http/dataset.rb', line 60 def (opts) __new__(config, .merge(opts)) end |
#with_params(params) ⇒ Object
76 77 78 |
# File 'lib/rom/http/dataset.rb', line 76 def with_params(params) (params: params) end |
#with_path(path) ⇒ Object
64 65 66 |
# File 'lib/rom/http/dataset.rb', line 64 def with_path(path) (path: path) end |
#with_request_method(request_method) ⇒ Object
72 73 74 |
# File 'lib/rom/http/dataset.rb', line 72 def with_request_method(request_method) (request_method: request_method) end |