Class: ROM::HTTP::Dataset

Inherits:
Object
  • Object
show all
Includes:
Enumerable, Options
Defined in:
lib/rom/http/dataset.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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, options = {})
  @config = config
  super(options)
end

Instance Attribute Details

#configObject (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_pathObject



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)
  with_options(path: options[:path] + '/' + path)
end

#deleteObject



99
100
101
102
103
# File 'lib/rom/http/dataset.rb', line 99

def delete
  with_options(
    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

#headersObject



36
37
38
# File 'lib/rom/http/dataset.rb', line 36

def headers
  config.fetch(:headers, {}).merge(options.fetch(:headers, {}))
end

#insert(params) ⇒ Object



85
86
87
88
89
90
# File 'lib/rom/http/dataset.rb', line 85

def insert(params)
  with_options(
    request_method: :post,
    params: params
  ).response
end

#nameObject



40
41
42
# File 'lib/rom/http/dataset.rb', line 40

def name
  config[:name].to_s
end

#pathObject



44
45
46
# File 'lib/rom/http/dataset.rb', line 44

def path
  options[:path].to_s.sub(%r{\A/}, '')
end

#responseObject



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)
  with_options(
    request_method: :put,
    params: params
  ).response
end

#uriObject



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, options.merge(headers: headers))
end

#with_options(opts) ⇒ Object



60
61
62
# File 'lib/rom/http/dataset.rb', line 60

def with_options(opts)
  __new__(config, options.merge(opts))
end

#with_params(params) ⇒ Object



76
77
78
# File 'lib/rom/http/dataset.rb', line 76

def with_params(params)
  with_options(params: params)
end

#with_path(path) ⇒ Object



64
65
66
# File 'lib/rom/http/dataset.rb', line 64

def with_path(path)
  with_options(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)
  with_options(request_method: request_method)
end