Class: Opi::Resource
- Inherits:
-
Object
- Object
- Opi::Resource
- Defined in:
- lib/opi/resource.rb
Instance Attribute Summary collapse
-
#after_filters ⇒ Object
readonly
Returns the value of attribute after_filters.
-
#before_filters ⇒ Object
readonly
Returns the value of attribute before_filters.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#resources ⇒ Object
readonly
Returns the value of attribute resources.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
-
#routes ⇒ Object
readonly
Returns the value of attribute routes.
Instance Method Summary collapse
- #after(method) ⇒ Object
- #before(method) ⇒ Object
- #delete(path = nil, options = {}, &block) ⇒ Object
- #get(path = nil, options = {}, &block) ⇒ Object
-
#initialize(root = '', options = {}, before = [], after = [], block = nil) ⇒ Resource
constructor
A new instance of Resource.
- #post(path = nil, options = {}, &block) ⇒ Object
- #put(path = nil, options = {}, &block) ⇒ Object
- #resource(path, options = {}, &block) ⇒ Object
Constructor Details
#initialize(root = '', options = {}, before = [], after = [], block = nil) ⇒ Resource
Returns a new instance of Resource.
5 6 7 8 9 10 11 12 13 |
# File 'lib/opi/resource.rb', line 5 def initialize(root='', ={}, before=[], after=[], block=nil) @root = root @options = @before_filters = before @after_filters = after @resources = [] @routes = [] instance_eval &block if block end |
Instance Attribute Details
#after_filters ⇒ Object (readonly)
Returns the value of attribute after_filters.
3 4 5 |
# File 'lib/opi/resource.rb', line 3 def after_filters @after_filters end |
#before_filters ⇒ Object (readonly)
Returns the value of attribute before_filters.
3 4 5 |
# File 'lib/opi/resource.rb', line 3 def before_filters @before_filters end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/opi/resource.rb', line 3 def @options end |
#resources ⇒ Object (readonly)
Returns the value of attribute resources.
3 4 5 |
# File 'lib/opi/resource.rb', line 3 def resources @resources end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
3 4 5 |
# File 'lib/opi/resource.rb', line 3 def root @root end |
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
3 4 5 |
# File 'lib/opi/resource.rb', line 3 def routes @routes end |
Instance Method Details
#after(method) ⇒ Object
35 36 37 |
# File 'lib/opi/resource.rb', line 35 def after(method) after_filters << method end |
#before(method) ⇒ Object
31 32 33 |
# File 'lib/opi/resource.rb', line 31 def before(method) before_filters << method end |
#delete(path = nil, options = {}, &block) ⇒ Object
27 28 29 |
# File 'lib/opi/resource.rb', line 27 def delete(path=nil, ={}, &block) route 'DELETE', path, , block end |
#get(path = nil, options = {}, &block) ⇒ Object
15 16 17 |
# File 'lib/opi/resource.rb', line 15 def get(path=nil, ={}, &block) route 'GET', path, , block end |
#post(path = nil, options = {}, &block) ⇒ Object
19 20 21 |
# File 'lib/opi/resource.rb', line 19 def post(path=nil, ={}, &block) route 'POST', path, , block end |
#put(path = nil, options = {}, &block) ⇒ Object
23 24 25 |
# File 'lib/opi/resource.rb', line 23 def put(path=nil, ={}, &block) route 'PUT', path, , block end |
#resource(path, options = {}, &block) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/opi/resource.rb', line 39 def resource(path, ={}, &block) # TODO: clean this up, should be able to determine the child resource path root = "#{self.root}/#{path}" # TODO: should be able to determine parent resource name, need to store name separately unless self.root.empty? # TODO: need to singularize ... parent_resource = self.root.split('/').last.gsub(/s$/, '') puts parent_resource root = "#{self.root}/:#{parent_resource}_id/#{path}" end resources << Resource.new( root, self..merge(), self.before_filters.dup, self.after_filters.dup, block ) end |