Class: ROM::HTTP::Dataset
- Inherits:
-
Object
- Object
- ROM::HTTP::Dataset
show all
- Includes:
- Enumerable, Options
- Defined in:
- lib/rom/http/dataset.rb,
lib/rom/http/dataset/response_transformers/schemad.rb,
lib/rom/http/dataset/response_transformers/schemaless.rb
Defined Under Namespace
Modules: ResponseTransformers
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(config, options = {}) ⇒ Dataset
Returns a new instance of Dataset.
31
32
33
34
35
|
# File 'lib/rom/http/dataset.rb', line 31
def initialize(config, options = {})
@config = config
@response_transformer = ResponseTransformers::Schemaless.new
super(options)
end
|
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
11
12
13
|
# File 'lib/rom/http/dataset.rb', line 11
def config
@config
end
|
Class Method Details
.default_request_handler(handler = Undefined) ⇒ Object
20
21
22
23
|
# File 'lib/rom/http/dataset.rb', line 20
def default_request_handler(handler = Undefined)
return @default_request_handler if Undefined === handler
@default_request_handler = handler
end
|
.default_response_handler(handler = Undefined) ⇒ Object
25
26
27
28
|
# File 'lib/rom/http/dataset.rb', line 25
def default_response_handler(handler = Undefined)
return @default_response_handler if Undefined === handler
@default_response_handler = handler
end
|
Instance Method Details
#absolute_path ⇒ Object
58
59
60
|
# File 'lib/rom/http/dataset.rb', line 58
def absolute_path
'/' + path
end
|
66
67
68
|
# File 'lib/rom/http/dataset.rb', line 66
def (, value)
(.merge( => value))
end
|
#append_path(path) ⇒ Object
86
87
88
|
# File 'lib/rom/http/dataset.rb', line 86
def append_path(path)
with_options(path: options[:path] + '/' + path)
end
|
#delete ⇒ Object
117
118
119
120
121
|
# File 'lib/rom/http/dataset.rb', line 117
def delete
with_options(
request_method: :delete
).response
end
|
#each(&block) ⇒ Object
98
99
100
101
|
# File 'lib/rom/http/dataset.rb', line 98
def each(&block)
return to_enum unless block_given?
response.each(&block)
end
|
46
47
48
|
# File 'lib/rom/http/dataset.rb', line 46
def
config.fetch(:headers, {}).merge(options.fetch(:headers, {}))
end
|
#insert(params) ⇒ Object
103
104
105
106
107
108
|
# File 'lib/rom/http/dataset.rb', line 103
def insert(params)
with_options(
request_method: :post,
params: params
).response
end
|
#name ⇒ Object
50
51
52
|
# File 'lib/rom/http/dataset.rb', line 50
def name
config[:name].to_s
end
|
#path ⇒ Object
54
55
56
|
# File 'lib/rom/http/dataset.rb', line 54
def path
options[:path].to_s.sub(%r{\A/}, '')
end
|
#project(*args) ⇒ Object
74
75
76
77
78
79
80
|
# File 'lib/rom/http/dataset.rb', line 74
def project(*args)
projections = args.first.is_a?(::Array) ? args.first : args
with_options(
projections: (self.projections + projections)
)
end
|
#response ⇒ Object
123
124
125
126
127
128
|
# File 'lib/rom/http/dataset.rb', line 123
def response
response_transformer.call(
response_handler.call(request_handler.call(self), self),
self
)
end
|
37
38
39
40
|
# File 'lib/rom/http/dataset.rb', line 37
def response_transformer(transformer = Undefined)
return @response_transformer if Undefined === transformer
@response_transformer = transformer
end
|
#update(params) ⇒ Object
110
111
112
113
114
115
|
# File 'lib/rom/http/dataset.rb', line 110
def update(params)
with_options(
request_method: :put,
params: params
).response
end
|
#uri ⇒ Object
42
43
44
|
# File 'lib/rom/http/dataset.rb', line 42
def uri
config.fetch(:uri) { fail Error, ':uri configuration missing' }
end
|
62
63
64
|
# File 'lib/rom/http/dataset.rb', line 62
def ()
__new__(config, options.merge(headers: ))
end
|
#with_options(opts) ⇒ Object
70
71
72
|
# File 'lib/rom/http/dataset.rb', line 70
def with_options(opts)
__new__(config, options.merge(opts))
end
|
#with_params(params) ⇒ Object
94
95
96
|
# File 'lib/rom/http/dataset.rb', line 94
def with_params(params)
with_options(params: params)
end
|
#with_path(path) ⇒ Object
82
83
84
|
# File 'lib/rom/http/dataset.rb', line 82
def with_path(path)
with_options(path: path)
end
|
#with_request_method(request_method) ⇒ Object
90
91
92
|
# File 'lib/rom/http/dataset.rb', line 90
def with_request_method(request_method)
with_options(request_method: request_method)
end
|