Class: RubyRest::Resource

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

.domainObject

Returns the domain implementation



18
19
20
# File 'lib/rubyrest/resource.rb', line 18

def self.domain
  @domain
end

Declares a new link



48
49
50
# File 'lib/rubyrest/resource.rb', line 48

def self.link modifiers
  self.links << modifiers
end

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_pointObject



33
34
35
# File 'lib/rubyrest/resource.rb', line 33

def self.mount_point
  @mount_point
end

.propsObject

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

#domainObject

Convenience method



23
24
25
# File 'lib/rubyrest/resource.rb', line 23

def domain
  self.class.domain
end

#to_sObject

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