Class: RubyRest::Resource::Base

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)

Direct Known Subclasses

Sequel

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#appObject (readonly)

Returns the value of attribute app.



11
12
13
# File 'lib/rubyrest/resource.rb', line 11

def app
  @app
end

#nameObject (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

Declares a new link



64
65
66
# File 'lib/rubyrest/resource.rb', line 64

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

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_pointObject



31
32
33
# File 'lib/rubyrest/resource.rb', line 31

def self.mount_point
  @mount_point
end

.mutable_propsObject

Returns the list of properties thqt can be updated



42
# File 'lib/rubyrest/resource.rb', line 42

def self.mutable_props; @mutable_props end

.propsObject

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


44
45
46
# File 'lib/rubyrest/resource.rb', line 44

def self.related opts
  self.related_resources[opts[:property]] =opts[:resource]  
end


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

def self.related_resources
  @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_sObject

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