Class: Bebop::ResourceRouter
- Inherits:
-
Object
- Object
- Bebop::ResourceRouter
- Defined in:
- lib/bebop/ext.rb
Instance Attribute Summary collapse
-
#routes ⇒ Object
Returns the value of attribute routes.
Instance Method Summary collapse
- #after(*params, &block) ⇒ Object
- #before(*params, &block) ⇒ Object
- #create(options = {}, &block) ⇒ Object
- #delete(route, options = {}, &block) ⇒ Object
- #destroy(options = {}, &block) ⇒ Object
- #edit(options = {}, &block) ⇒ Object
- #get(route, options = {}, &block) ⇒ Object
- #head(route, options = {}, &block) ⇒ Object
- #index(options = {}, &block) ⇒ Object
-
#initialize(parent_resources = [], before_all = [], after_all = []) ⇒ ResourceRouter
constructor
A new instance of ResourceRouter.
- #logger ⇒ Object
- #logger=(val) ⇒ Object
- #new(options = {}, &block) ⇒ Object
- #post(route, options = {}, &block) ⇒ Object
- #print ⇒ Object
- #put(route, options = {}, &block) ⇒ Object
- #resource(name) {|router| ... } ⇒ Object
- #show(route = nil, options = {}, &block) ⇒ Object
- #update(options = {}, &block) ⇒ Object
Constructor Details
#initialize(parent_resources = [], before_all = [], after_all = []) ⇒ ResourceRouter
Returns a new instance of ResourceRouter.
40 41 42 43 44 |
# File 'lib/bebop/ext.rb', line 40 def initialize(parent_resources=[], before_all=[], after_all=[]) @current_resource = parent_resources.pop @parent_resources = parent_resources @before, @after, @routes = before_all, after_all, [] end |
Instance Attribute Details
#routes ⇒ Object
Returns the value of attribute routes.
30 31 32 |
# File 'lib/bebop/ext.rb', line 30 def routes @routes end |
Instance Method Details
#after(*params, &block) ⇒ Object
98 99 100 |
# File 'lib/bebop/ext.rb', line 98 def after(*params, &block) add_filter(@after, params, block) end |
#before(*params, &block) ⇒ Object
94 95 96 |
# File 'lib/bebop/ext.rb', line 94 def before(*params, &block) add_filter(@before, params, block) end |
#create(options = {}, &block) ⇒ Object
70 71 72 |
# File 'lib/bebop/ext.rb', line 70 def create(={}, &block) post '' , .merge(:identifier => :create), &block end |
#delete(route, options = {}, &block) ⇒ Object
58 59 60 |
# File 'lib/bebop/ext.rb', line 58 def delete(route, ={}, &block) add_route(:delete, route, , block) end |
#destroy(options = {}, &block) ⇒ Object
86 87 88 |
# File 'lib/bebop/ext.rb', line 86 def destroy(={}, &block) delete resource_identifier, .merge(:identifier => :destroy), &block end |
#edit(options = {}, &block) ⇒ Object
74 75 76 |
# File 'lib/bebop/ext.rb', line 74 def edit(={}, &block) get append_token(resource_identifier, 'edit') , .merge(:identifier => :edit), &block end |
#get(route, options = {}, &block) ⇒ Object
46 47 48 |
# File 'lib/bebop/ext.rb', line 46 def get(route, ={}, &block) add_route(:get, route, , block) end |
#head(route, options = {}, &block) ⇒ Object
62 63 64 |
# File 'lib/bebop/ext.rb', line 62 def head(route, ={}, &block) add_route(:head, route, , block) end |
#index(options = {}, &block) ⇒ Object
78 79 80 |
# File 'lib/bebop/ext.rb', line 78 def index(={}, &block) get '', .merge(:identifier => :index), &block end |
#logger ⇒ Object
32 33 34 |
# File 'lib/bebop/ext.rb', line 32 def logger @@logger ||= Logger.new(STDOUT) end |
#logger=(val) ⇒ Object
36 37 38 |
# File 'lib/bebop/ext.rb', line 36 def logger=(val) @@logger = val end |
#new(options = {}, &block) ⇒ Object
66 67 68 |
# File 'lib/bebop/ext.rb', line 66 def new(={}, &block) get 'new', .merge(:identifier => :new), &block end |
#post(route, options = {}, &block) ⇒ Object
54 55 56 |
# File 'lib/bebop/ext.rb', line 54 def post(route, ={}, &block) add_route(:post, route, , block) end |
#print ⇒ Object
111 112 113 114 115 116 117 118 119 |
# File 'lib/bebop/ext.rb', line 111 def print #TODO 6! 6! Block parameters, Ah Ah Ah! -> probably need route objects @routes.each do |method, route, , block, helper, identifier| logger.info "#{route}" logger.info " method: #{method.to_s.upcase}" logger.info " helper: #{helper}" if helper logger.info " identifier: #{identifier} " if identifier end end |
#put(route, options = {}, &block) ⇒ Object
50 51 52 |
# File 'lib/bebop/ext.rb', line 50 def put(route, ={}, &block) add_route(:put, route, , block) end |
#resource(name) {|router| ... } ⇒ Object
102 103 104 105 106 107 108 109 |
# File 'lib/bebop/ext.rb', line 102 def resource(name, &block) before_filters = filters(@before, :all, name) after_filters = filters(@after, :all, name) router = self.class.new(all_resources + [name], before_filters, after_filters) yield(router) @routes += router.routes end |
#show(route = nil, options = {}, &block) ⇒ Object
82 83 84 |
# File 'lib/bebop/ext.rb', line 82 def show(route=nil, ={}, &block) get append_token(resource_identifier, (route || '').to_s), .merge(:identifier => route || :show), &block end |
#update(options = {}, &block) ⇒ Object
90 91 92 |
# File 'lib/bebop/ext.rb', line 90 def update(={}, &block) put resource_identifier, .merge(:identifier => :update), &block end |