Class: Webmachine::Resource
- Inherits:
-
Object
- Object
- Webmachine::Resource
- Includes:
- Callbacks, Encodings
- Defined in:
- lib/webmachine/resource.rb,
lib/webmachine/resource/callbacks.rb,
lib/webmachine/resource/encodings.rb
Overview
Resource is the primary building block of Webmachine applications, and describes families of HTTP resources. It includes all of the methods you might want to override to customize the behavior of the resource. The simplest resource family you can implement looks like this:
class HelloWorldResource < Webmachine::Resource
def to_html
"<html><body>Hello, world!</body></html>"
end
end
For more information about how response decisions are made in Webmachine based on your resource class, refer to the diagram at http://webmachine.basho.com/images/http-headers-status-v3.png.
Defined Under Namespace
Instance Attribute Summary (collapse)
-
- (Object) request
readonly
Returns the value of attribute request.
-
- (Object) response
readonly
Returns the value of attribute response.
Class Method Summary (collapse)
-
+ (Resource) new(request, response)
Creates a new Resource, initializing it with the request and response.
Methods included from Encodings
#encode_deflate, #encode_gzip, #encode_identity
Methods included from Callbacks
#allow_missing_post?, #allowed_methods, #base_uri, #charsets_provided, #content_types_accepted, #content_types_provided, #create_path, #delete_completed?, #delete_resource, #encodings_provided, #expires, #finish_request, #forbidden?, #generate_etag, #is_authorized?, #is_conflict?, #known_content_type?, #known_methods, #language_available?, #last_modified, #malformed_request?, #moved_permanently?, #moved_temporarily?, #multiple_choices?, #options, #post_is_create?, #previously_existed?, #process_post, #resource_exists?, #service_available?, #uri_too_long?, #valid_content_headers?, #valid_entity_length?, #validate_content_checksum, #variances
Instance Attribute Details
- (Object) request (readonly)
Returns the value of attribute request
24 25 26 |
# File 'lib/webmachine/resource.rb', line 24 def request @request end |
- (Object) response (readonly)
Returns the value of attribute response
24 25 26 |
# File 'lib/webmachine/resource.rb', line 24 def response @response end |
Class Method Details
+ (Resource) new(request, response)
Creates a new Webmachine::Resource, initializing it with the request and response. Note that you may still override #initialize to initialize your resource. It will be called after the request and response ivars are set.
33 34 35 36 37 38 39 |
# File 'lib/webmachine/resource.rb', line 33 def self.new(request, response) instance = allocate instance.instance_variable_set(:@request, request) instance.instance_variable_set(:@response, response) instance.send :initialize instance end |