Class: Klient::Resource
- Inherits:
-
Object
- Object
- Klient::Resource
- Extended by:
- ResourceMethods
- Defined in:
- lib/klient/resource.rb
Class Attribute Summary collapse
-
.arguments ⇒ Object
Returns the value of attribute arguments.
-
.collection_accessor ⇒ Object
readonly
Returns the value of attribute collection_accessor.
-
.id ⇒ Object
readonly
Returns the value of attribute id.
-
.identifier ⇒ Object
readonly
Returns the value of attribute identifier.
-
.mapping ⇒ Object
readonly
Returns the value of attribute mapping.
-
.resource_type ⇒ Object
Returns the value of attribute resource_type.
-
.type ⇒ Object
Returns the value of attribute type.
-
.url_template ⇒ Object
readonly
Returns the value of attribute url_template.
Instance Attribute Summary collapse
-
#collection_accessor ⇒ Object
readonly
Returns the value of attribute collection_accessor.
-
#header_proc ⇒ Object
readonly
Returns the value of attribute header_proc.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#last_response ⇒ Object
readonly
Returns the value of attribute last_response.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#url_arguments ⇒ Object
readonly
Returns the value of attribute url_arguments.
-
#url_template ⇒ Object
readonly
Returns the value of attribute url_template.
Instance Method Summary collapse
-
#initialize(parent) ⇒ Resource
constructor
A new instance of Resource.
- #inspect ⇒ Object
Methods included from ResourceMethods
collection, default_collection_accessor, resource, resources
Constructor Details
#initialize(parent) ⇒ Resource
Returns a new instance of Resource.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/klient/resource.rb', line 15 def initialize(parent) @root = parent.root @header_proc = parent.header_proc @regexp = /#{self.class.name.demodulize.underscore.gsub(/(_|-|\s+)/, "(_|-|\s*)")}/i @id = self.class.try(:id) @collection_accessor = @identifier = self.class.try(:identifier) if @id @url_arguments = {@id => @identifier} else @url_arguments = {} end @parent = parent @headers = {} @url_template = Addressable::Template.new( @parent.url + self.class.url_template.pattern ) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(mth, *args, &block) ⇒ Object (private)
106 107 108 109 110 111 112 |
# File 'lib/klient/resource.rb', line 106 def method_missing(mth, *args, &block) if @parsed_body.respond_to?(mth) @parsed_body.send(mth, *args, &block) else @last_response.send(mth, *args, &block) end end |
Class Attribute Details
.arguments ⇒ Object
Returns the value of attribute arguments.
10 11 12 |
# File 'lib/klient/resource.rb', line 10 def arguments @arguments end |
.collection_accessor ⇒ Object (readonly)
Returns the value of attribute collection_accessor.
9 10 11 |
# File 'lib/klient/resource.rb', line 9 def collection_accessor @collection_accessor end |
.id ⇒ Object (readonly)
Returns the value of attribute id.
9 10 11 |
# File 'lib/klient/resource.rb', line 9 def id @id end |
.identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
9 10 11 |
# File 'lib/klient/resource.rb', line 9 def identifier @identifier end |
.mapping ⇒ Object (readonly)
Returns the value of attribute mapping.
9 10 11 |
# File 'lib/klient/resource.rb', line 9 def mapping @mapping end |
.resource_type ⇒ Object
Returns the value of attribute resource_type.
10 11 12 |
# File 'lib/klient/resource.rb', line 10 def resource_type @resource_type end |
.type ⇒ Object
Returns the value of attribute type.
10 11 12 |
# File 'lib/klient/resource.rb', line 10 def type @type end |
.url_template ⇒ Object (readonly)
Returns the value of attribute url_template.
9 10 11 |
# File 'lib/klient/resource.rb', line 9 def url_template @url_template end |
Instance Attribute Details
#collection_accessor ⇒ Object (readonly)
Returns the value of attribute collection_accessor.
6 7 8 |
# File 'lib/klient/resource.rb', line 6 def collection_accessor @collection_accessor end |
#header_proc ⇒ Object (readonly)
Returns the value of attribute header_proc.
6 7 8 |
# File 'lib/klient/resource.rb', line 6 def header_proc @header_proc end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
6 7 8 |
# File 'lib/klient/resource.rb', line 6 def headers @headers end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/klient/resource.rb', line 6 def id @id end |
#last_response ⇒ Object (readonly)
Returns the value of attribute last_response.
6 7 8 |
# File 'lib/klient/resource.rb', line 6 def last_response @last_response end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
6 7 8 |
# File 'lib/klient/resource.rb', line 6 def parent @parent end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
6 7 8 |
# File 'lib/klient/resource.rb', line 6 def root @root end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
6 7 8 |
# File 'lib/klient/resource.rb', line 6 def status @status end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
6 7 8 |
# File 'lib/klient/resource.rb', line 6 def url @url end |
#url_arguments ⇒ Object (readonly)
Returns the value of attribute url_arguments.
6 7 8 |
# File 'lib/klient/resource.rb', line 6 def url_arguments @url_arguments end |
#url_template ⇒ Object (readonly)
Returns the value of attribute url_template.
6 7 8 |
# File 'lib/klient/resource.rb', line 6 def url_template @url_template end |
Instance Method Details
#inspect ⇒ Object
36 37 38 |
# File 'lib/klient/resource.rb', line 36 def inspect "#<#{self.class.name}:#{object_id} @url=#{self.url.inspect} @status_code=#{self.last_response.try(:status) || 'nil'}>" end |