Class: ROM::HTTP::Dataset
- Inherits:
-
Object
- Object
- ROM::HTTP::Dataset
- Includes:
- Enumerable
- Defined in:
- lib/rom/http/dataset.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
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
- #params ⇒ Object
- #path ⇒ Object
- #request_method ⇒ 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.
9 10 11 12 13 14 15 16 |
# File 'lib/rom/http/dataset.rb', line 9 def initialize(config, = {}) @config = config @options = { request_method: :get, path: '', params: {} }.merge() end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
7 8 9 |
# File 'lib/rom/http/dataset.rb', line 7 def config @config end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/rom/http/dataset.rb', line 7 def @options end |
Instance Method Details
#absolute_path ⇒ Object
34 35 36 |
# File 'lib/rom/http/dataset.rb', line 34 def absolute_path '/' + path end |
#add_header(header, value) ⇒ Object
50 51 52 |
# File 'lib/rom/http/dataset.rb', line 50 def add_header(header, value) with_headers(headers.merge(header => value)) end |
#append_path(path) ⇒ Object
62 63 64 |
# File 'lib/rom/http/dataset.rb', line 62 def append_path(path) (path: [:path] + '/' + path) end |
#delete ⇒ Object
93 94 95 96 97 |
# File 'lib/rom/http/dataset.rb', line 93 def delete ( request_method: :delete ).response end |
#each(&block) ⇒ Object
74 75 76 77 |
# File 'lib/rom/http/dataset.rb', line 74 def each(&block) return to_enum unless block_given? response.each(&block) end |
#headers ⇒ Object
22 23 24 |
# File 'lib/rom/http/dataset.rb', line 22 def headers config.fetch(:headers, {}).merge(.fetch(:headers, {})) end |
#insert(params) ⇒ Object
79 80 81 82 83 84 |
# File 'lib/rom/http/dataset.rb', line 79 def insert(params) ( request_method: :post, params: params ).response end |
#name ⇒ Object
26 27 28 |
# File 'lib/rom/http/dataset.rb', line 26 def name config[:name].to_s end |
#params ⇒ Object
42 43 44 |
# File 'lib/rom/http/dataset.rb', line 42 def params [:params] end |
#path ⇒ Object
30 31 32 |
# File 'lib/rom/http/dataset.rb', line 30 def path [:path].to_s.sub(%r{\A/}, '') end |
#request_method ⇒ Object
38 39 40 |
# File 'lib/rom/http/dataset.rb', line 38 def request_method [:request_method] end |
#response ⇒ Object
99 100 101 |
# File 'lib/rom/http/dataset.rb', line 99 def response response_handler.call(request_handler.call(self), self) end |
#update(params) ⇒ Object
86 87 88 89 90 91 |
# File 'lib/rom/http/dataset.rb', line 86 def update(params) ( request_method: :put, params: params ).response end |
#uri ⇒ Object
18 19 20 |
# File 'lib/rom/http/dataset.rb', line 18 def uri config[:uri] end |
#with_headers(headers) ⇒ Object
46 47 48 |
# File 'lib/rom/http/dataset.rb', line 46 def with_headers(headers) self.class.new(config, .merge(headers: headers)) end |
#with_options(opts) ⇒ Object
54 55 56 |
# File 'lib/rom/http/dataset.rb', line 54 def (opts) self.class.new(config, .merge(opts)) end |
#with_params(params) ⇒ Object
70 71 72 |
# File 'lib/rom/http/dataset.rb', line 70 def with_params(params) (params: params) end |
#with_path(path) ⇒ Object
58 59 60 |
# File 'lib/rom/http/dataset.rb', line 58 def with_path(path) (path: path) end |
#with_request_method(request_method) ⇒ Object
66 67 68 |
# File 'lib/rom/http/dataset.rb', line 66 def with_request_method(request_method) (request_method: request_method) end |