Module: HyperResource::Modules::ConfigAttributes::ClassMethods

Defined in:
lib/hyper_resource/modules/config_attributes.rb

Instance Method Summary collapse

Instance Method Details

#adapterObject

Returns the adapter class for this resource class.



222
223
224
# File 'lib/hyper_resource/modules/config_attributes.rb', line 222

def adapter
  cfg_get(:adapter) || HyperResource::Adapter::HAL_JSON
end

#adapter=(v) ⇒ Object

Sets the adapter class for this resource class.



233
234
235
# File 'lib/hyper_resource/modules/config_attributes.rb', line 233

def adapter=(v)
  cfg_set(:adapter, v)
end

#adapter_for_url(url) ⇒ Object

Returns the adapter class for the given url.



227
228
229
230
# File 'lib/hyper_resource/modules/config_attributes.rb', line 227

def adapter_for_url(url)
  self.hr_config.get_for_url(url, :adapter) ||
    HyperResource::Adapter::HAL_JSON
end

#authObject

Returns the auth config hash for this resource class.



172
173
174
# File 'lib/hyper_resource/modules/config_attributes.rb', line 172

def auth
  cfg_get(:auth)
end

#auth=(v) ⇒ Object

Sets the auth config hash for this resource class. Currently only the format ‘=> [’username’, ‘password’]‘ is supported.



184
185
186
# File 'lib/hyper_resource/modules/config_attributes.rb', line 184

def auth=(v)
  cfg_set(:auth, v)
end

#auth_for_url(url) ⇒ Object

Returns the auth config hash for the given url.



177
178
179
# File 'lib/hyper_resource/modules/config_attributes.rb', line 177

def auth_for_url(url)
  self.hr_config.get_for_url(url, :auth)
end

#config(hash = nil) ⇒ Object

When called with no arguments, returns this class’s Configuration. When called with a hash, applies the given configuration parameters to this resource’s Configuration. ‘hash` must be in the form:

{'hostmask' => {'key1' => 'value1', 'key2' => 'value2', ...}}

Valid keys are ‘auth`, `headers`, `namespace`, `adapter`, and `faraday_options`.



165
166
167
168
# File 'lib/hyper_resource/modules/config_attributes.rb', line 165

def config(hash=nil)
  return hr_config unless hash
  hr_config.config(hash)
end

#default_attributesObject

Returns the hash of default attributes for this resource class.



239
240
241
# File 'lib/hyper_resource/modules/config_attributes.rb', line 239

def default_attributes
  cfg_get(:default_attributes)
end

#default_attributes=(v) ⇒ Object

Sets the hash of default attributes for this resource class. These attributes will be passed along with every HTTP request.



250
251
252
# File 'lib/hyper_resource/modules/config_attributes.rb', line 250

def default_attributes=(v)
  cfg_set(:default_attributes, v)
end

#default_attributes_for_url(url) ⇒ Object

Returns the hash of default attributes for the given url.



244
245
246
# File 'lib/hyper_resource/modules/config_attributes.rb', line 244

def default_attributes_for_url(url)
  self.hr_config.get_for_url(url, :default_attributes)
end

#faraday_optionsObject

Returns the Faraday connection options hash for this resource class.



256
257
258
# File 'lib/hyper_resource/modules/config_attributes.rb', line 256

def faraday_options
  cfg_get(:faraday_options)
end

#faraday_options=(v) ⇒ Object

Sets the Faraday connection options hash for this resource class. These options will be used for all HTTP requests.



267
268
269
# File 'lib/hyper_resource/modules/config_attributes.rb', line 267

def faraday_options=(v)
  cfg_set(:faraday_options, v)
end

#faraday_options_for_url(url) ⇒ Object

Returns the Faraday connection options hash for this resource class.



261
262
263
# File 'lib/hyper_resource/modules/config_attributes.rb', line 261

def faraday_options_for_url(url)
  self.hr_config.get_for_url(url, :faraday_options)
end

#headersObject

Returns the headers hash for this resource class.



190
191
192
# File 'lib/hyper_resource/modules/config_attributes.rb', line 190

def headers
  cfg_get(:headers)
end

#headers=(v) ⇒ Object

Sets the headers hash for this resource class.



200
201
202
# File 'lib/hyper_resource/modules/config_attributes.rb', line 200

def headers=(v)
  cfg_set(:headers, v)
end

#headers_for_url(url) ⇒ Object

Returns the headers hash for the given url.



195
196
197
# File 'lib/hyper_resource/modules/config_attributes.rb', line 195

def headers_for_url(url)
  self.hr_config.get_for_url(url, :headers)
end

#hr_configObject



155
156
157
# File 'lib/hyper_resource/modules/config_attributes.rb', line 155

def hr_config
  @hr_config ||= self::Configuration.new
end

#namespaceObject

Returns the namespace string/class for this resource class.



206
207
208
# File 'lib/hyper_resource/modules/config_attributes.rb', line 206

def namespace
  cfg_get(:namespace)
end

#namespace=(v) ⇒ Object

Sets the namespace string/class for this resource class.



216
217
218
# File 'lib/hyper_resource/modules/config_attributes.rb', line 216

def namespace=(v)
  cfg_set(:namespace, v)
end

#namespace_for_url(url) ⇒ Object

Returns the namespace string/class for the given url.



211
212
213
# File 'lib/hyper_resource/modules/config_attributes.rb', line 211

def namespace_for_url(url)
  self.hr_config.get_for_url(url, :namespace)
end