Class: Wrest::Resource::Base
Overview
Resource::Base is the equivalent of ActiveResource::Base.
It is a REST client targetted at Rails REST apps.
Instance Attribute Summary collapse
Class Method Summary
collapse
build_attribute_getter, build_attribute_queryer, build_attribute_setter, included
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
18
19
20
|
# File 'lib/wrest/resource/base.rb', line 18
def attributes
@attributes
end
|
Class Method Details
.find(id) ⇒ Object
59
60
61
62
63
64
65
66
67
|
# File 'lib/wrest/resource/base.rb', line 59
def find(id)
response_hash = "#{resource_url}/#{id}".to_uri.get.deserialise
resource_type = response_hash.keys.first
if(resource_type.underscore.camelize == self.name)
self.new(response_hash[resource_type].first)
else
response_hash
end
end
|
.find_all ⇒ Object
56
57
|
# File 'lib/wrest/resource/base.rb', line 56
def find_all
end
|
.inherited(klass) ⇒ Object
21
22
23
|
# File 'lib/wrest/resource/base.rb', line 21
def inherited(klass)
klass.set_resource_name klass.name
end
|
.objectify(hash) ⇒ Object
69
70
|
# File 'lib/wrest/resource/base.rb', line 69
def objectify(hash)
end
|
.resource_path ⇒ Object
48
49
50
|
# File 'lib/wrest/resource/base.rb', line 48
def resource_path
@resource_path ||= "/#{resource_name.underscore.pluralize}"
end
|
.resource_url ⇒ Object
52
53
54
|
# File 'lib/wrest/resource/base.rb', line 52
def resource_url
"#{host}#{resource_path}"
end
|
.set_host(host) ⇒ Object
41
42
43
|
# File 'lib/wrest/resource/base.rb', line 41
def set_host(host)
self.class_eval "def self.host; '#{host}';end"
end
|
.set_redirect_handler(method_object) ⇒ Object
45
46
|
# File 'lib/wrest/resource/base.rb', line 45
def set_redirect_handler(method_object)
end
|
.set_resource_name(resource_name) ⇒ Object
Allows the resource name to be configured and creates
a getter method for it.
This is a useful feature when using anonymous classes like
we often do while writing tests.
By default, the resource name is set to the name of the class.
30
31
32
|
# File 'lib/wrest/resource/base.rb', line 30
def set_resource_name(resource_name)
self.class_eval "def self.resource_name; '#{resource_name}';end"
end
|