Class: RubyRest::Resource
- Inherits:
-
Object
- Object
- RubyRest::Resource
- Defined in:
- lib/rubyrest/resource.rb
Overview
Base REST Resource class that acts as a wrapper for the actual business logic, data formatting (response time) and validations (request time)
Class Method Summary collapse
- .atom(modifiers) ⇒ Object
-
.domain ⇒ Object
Returns the domain implementation.
-
.link(modifiers) ⇒ Object
Declares a new link.
-
.links ⇒ Object
Returns the array of links declared for the resource.
- .mount_point ⇒ Object
-
.props ⇒ Object
Returns the list of formatters.
-
.set_domain(domain_klass) ⇒ Object
Sets the domain implementation for this resource.
-
.with_mount_point(path) ⇒ Object
Defines the url type the resource is going to handle.
Instance Method Summary collapse
-
#bind(object, xml) ⇒ Object
Updates the specified object with the data found in the specified xml object, and the rules defined in the resource parsers.
-
#domain ⇒ Object
Convenience method.
-
#initialize(app) ⇒ Resource
constructor
Creates a new resource, under the given application.
-
#to_s ⇒ Object
String representation of a resource.
Constructor Details
#initialize(app) ⇒ Resource
Creates a new resource, under the given application
8 9 10 |
# File 'lib/rubyrest/resource.rb', line 8 def initialize( app ) @app = app end |
Class Method Details
.atom(modifiers) ⇒ Object
37 38 39 |
# File 'lib/rubyrest/resource.rb', line 37 def self.atom modifiers self.props << modifiers end |
.domain ⇒ Object
Returns the domain implementation
18 19 20 |
# File 'lib/rubyrest/resource.rb', line 18 def self.domain @domain end |
.link(modifiers) ⇒ Object
Declares a new link
48 49 50 |
# File 'lib/rubyrest/resource.rb', line 48 def self.link modifiers self.links << modifiers end |
.links ⇒ Object
Returns the array of links declared for the resource
54 55 56 57 |
# File 'lib/rubyrest/resource.rb', line 54 def self.links @links = [] if !@links return @links end |
.mount_point ⇒ Object
33 34 35 |
# File 'lib/rubyrest/resource.rb', line 33 def self.mount_point @mount_point end |
.props ⇒ Object
Returns the list of formatters
42 43 44 45 |
# File 'lib/rubyrest/resource.rb', line 42 def self.props @props = [] if !@props return @props end |
.set_domain(domain_klass) ⇒ Object
Sets the domain implementation for this resource
13 14 15 |
# File 'lib/rubyrest/resource.rb', line 13 def self.set_domain domain_klass @domain = domain_klass end |
.with_mount_point(path) ⇒ Object
Defines the url type the resource is going to handle
29 30 31 |
# File 'lib/rubyrest/resource.rb', line 29 def self.with_mount_point path @mount_point = path end |
Instance Method Details
#bind(object, xml) ⇒ Object
Updates the specified object with the data found in the specified xml object, and the rules defined in the resource parsers
62 63 64 65 66 67 |
# File 'lib/rubyrest/resource.rb', line 62 def bind( object, xml ) self.class.props.each{ |p| @app.formatter(p).property( p ).parse( object, p, xml ) } return object end |
#domain ⇒ Object
Convenience method
23 24 25 |
# File 'lib/rubyrest/resource.rb', line 23 def domain self.class.domain end |
#to_s ⇒ Object
String representation of a resource
70 71 72 |
# File 'lib/rubyrest/resource.rb', line 70 def to_s "path #{self.class.mount_point}, domain #{self.domain}" end |