Class: RubyRest::Resource::Base
- Inherits:
-
Object
- Object
- RubyRest::Resource::Base
- 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)
Direct Known Subclasses
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
- .atom(modifiers) ⇒ Object
-
.link(modifiers) ⇒ Object
Declares a new link.
-
.links ⇒ Object
Returns the array of links declared for the resource.
- .mount_point ⇒ Object
-
.mutable_props ⇒ Object
Returns the list of properties thqt can be updated.
-
.props ⇒ Object
Returns the list of formatters.
- .related(opts) ⇒ Object
- .related_resources ⇒ Object
-
.with_mount_point(path) ⇒ Object
Defines the url type the resource is going to handle.
-
.with_mutable_props(*props) ⇒ Object
Sets the list of properties thqt can be updated.
Instance Method Summary collapse
-
#initialize(app, name) ⇒ Base
constructor
Creates a new resource, under the given application.
-
#resource(name) ⇒ Object
Shortcut method to access other resources.
-
#to_s ⇒ Object
String representation of a resource.
Constructor Details
#initialize(app, name) ⇒ Base
Creates a new resource, under the given application
14 15 16 17 18 |
# File 'lib/rubyrest/resource.rb', line 14 def initialize( app, name ) @app = app @logger = app.logger @name = name end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
11 12 13 |
# File 'lib/rubyrest/resource.rb', line 11 def app @app end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/rubyrest/resource.rb', line 11 def name @name end |
Class Method Details
.atom(modifiers) ⇒ Object
53 54 55 |
# File 'lib/rubyrest/resource.rb', line 53 def self.atom modifiers self.props << modifiers end |
.link(modifiers) ⇒ Object
Declares a new link
64 65 66 |
# File 'lib/rubyrest/resource.rb', line 64 def self.link modifiers self.links << modifiers end |
.links ⇒ Object
Returns the array of links declared for the resource
70 71 72 73 |
# File 'lib/rubyrest/resource.rb', line 70 def self.links @links = [] if !@links return @links end |
.mount_point ⇒ Object
31 32 33 |
# File 'lib/rubyrest/resource.rb', line 31 def self.mount_point @mount_point end |
.mutable_props ⇒ Object
Returns the list of properties thqt can be updated
42 |
# File 'lib/rubyrest/resource.rb', line 42 def self.mutable_props; @mutable_props end |
.props ⇒ Object
Returns the list of formatters
58 59 60 61 |
# File 'lib/rubyrest/resource.rb', line 58 def self.props @props = [] if !@props return @props end |
.related(opts) ⇒ Object
44 45 46 |
# File 'lib/rubyrest/resource.rb', line 44 def self. opts self.[opts[:property]] =opts[:resource] end |
.related_resources ⇒ Object
48 49 50 51 |
# File 'lib/rubyrest/resource.rb', line 48 def self. @related_resources = Hash.new if !@related_resources return @related_resources end |
.with_mount_point(path) ⇒ Object
Defines the url type the resource is going to handle
27 28 29 |
# File 'lib/rubyrest/resource.rb', line 27 def self.with_mount_point path @mount_point = path end |
.with_mutable_props(*props) ⇒ Object
Sets the list of properties thqt can be updated
36 37 38 |
# File 'lib/rubyrest/resource.rb', line 36 def self.with_mutable_props *props @mutable_props = *props end |
Instance Method Details
#resource(name) ⇒ Object
Shortcut method to access other resources
21 22 23 |
# File 'lib/rubyrest/resource.rb', line 21 def resource( name ) @app.resource( name ) end |
#to_s ⇒ Object
String representation of a resource
76 77 78 |
# File 'lib/rubyrest/resource.rb', line 76 def to_s "path #{self.class.mount_point}, class #{self.class}" end |