Class: Wrest::Mappers::Resource::Base
- Inherits:
-
Object
- Object
- Wrest::Mappers::Resource::Base
show all
- Includes:
- AttributesContainer
- Defined in:
- lib/wrest/mappers/resource/base.rb
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.
17
18
19
|
# File 'lib/wrest/mappers/resource/base.rb', line 17
def attributes
@attributes
end
|
Class Method Details
.find(id) ⇒ Object
55
56
57
58
59
60
61
62
63
|
# File 'lib/wrest/mappers/resource/base.rb', line 55
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
52
53
|
# File 'lib/wrest/mappers/resource/base.rb', line 52
def find_all
end
|
.inherited(klass) ⇒ Object
20
21
22
|
# File 'lib/wrest/mappers/resource/base.rb', line 20
def inherited(klass)
klass.set_resource_name klass.name
end
|
.objectify(hash) ⇒ Object
65
66
|
# File 'lib/wrest/mappers/resource/base.rb', line 65
def objectify(hash)
end
|
.resource_path ⇒ Object
44
45
46
|
# File 'lib/wrest/mappers/resource/base.rb', line 44
def resource_path
@resource_path ||= "/#{resource_name.underscore.pluralize}"
end
|
.resource_url ⇒ Object
48
49
50
|
# File 'lib/wrest/mappers/resource/base.rb', line 48
def resource_url
"#{host}#{resource_path}"
end
|
.set_host(host) ⇒ Object
40
41
42
|
# File 'lib/wrest/mappers/resource/base.rb', line 40
def set_host(host)
self.class_eval "def self.host; '#{host}';end"
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.
29
30
31
|
# File 'lib/wrest/mappers/resource/base.rb', line 29
def set_resource_name(resource_name)
self.class_eval "def self.resource_name; '#{resource_name}';end"
end
|