Class: Cardiac::Subresource

Inherits:
Resource show all
Defined in:
lib/cardiac/resource/subresource.rb

Overview

If a subresource has any path or query values, it will treat the base resource’s path as being a directory.

Constant Summary

Constants included from CodecMethods

CodecMethods::DEFAULT_DECODERS

Constants included from RequestMethods

RequestMethods::DEFAULT_ACCEPTS

Instance Attribute Summary

Attributes inherited from Resource

#accepts_values, #decoders_values, #encoder_handler_value, #encoder_search_value, #extensions_values, #headers_values, #host_value, #https_value, #method_value, #operations_values, #options_values, #password_value, #path_values, #port_value, #query_values, #subresources_values, #user_value

Instance Method Summary collapse

Methods inherited from Resource

#to_reflection, #to_resource, #to_s

Methods included from ConfigMethods

#reconfig, #reconfigure

Methods included from ExtensionMethods

#__extension_defined__?, #__extension_module__, #extending, #operation, #subresource

Methods included from CodecMethods

#decoders, #encoder, #reset_decoders

Methods included from RequestMethods

#accepts, #at, #header, #headers, #http_method, #option, #options, #request_has_body?, #request_is_idemptotent?, #request_is_safe?, #reset_headers, #reset_options, #response_has_body?

Methods included from UriMethods

#at, #host, #http, #http_method, #https, #password, #path, #port, #query, #reset_query, #scheme, #ssl, #to_relative_uri, #to_relative_url, #to_uri, #to_url, #user, #userinfo

Constructor Details

#initialize(base) ⇒ Subresource

Returns a new instance of Subresource.



7
8
9
10
11
# File 'lib/cardiac/resource/subresource.rb', line 7

def initialize(base)
  @_base_resource = base
  super base.base_value
  self.method_value = base.method_value
end

Instance Method Details

#__parent_module__Object

Lazily builds the parent module, then redefines this method as an attr_reader.



21
22
23
24
25
# File 'lib/cardiac/resource/subresource.rb', line 21

def __parent_module__
  build_parent_module
ensure
  singleton_class.class_eval "attr_reader :__parent_module__"
end

#base_valueObject

Overridden to enforce the appending of subresource paths.



14
15
16
17
18
# File 'lib/cardiac/resource/subresource.rb', line 14

def base_value
  base_path = @_base_resource.build_path
  base_path+='/' if @path_values.any? && base_path[-1]!='/'
  super.merge URI::Generic.build(path: base_path)
end