bebop 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'bebop'
3
- s.version = '0.1.1'
3
+ s.version = '0.1.2'
4
4
  s.date = '2010-1-10'
5
5
 
6
6
  s.summary = s.description = "A small Sinatra/Monk extension for resource routing"
@@ -1,4 +1,6 @@
1
1
  libdir = File.dirname(__FILE__)
2
2
  $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
3
3
 
4
+ require 'logger'
5
+ require 'active_support'
4
6
  require 'bebop/ext'
@@ -1,8 +1,7 @@
1
- require 'active_support'
2
-
3
1
  module Bebop
4
2
  class InvalidPathArgumentError < ArgumentError; end
5
3
  PARAM_REGEX = /:[a-zA-Z0-9_]+/
4
+
6
5
 
7
6
  def resource(name, &block)
8
7
  resource = ResourceRouter.new
@@ -28,10 +27,30 @@ module Bebop
28
27
  end
29
28
  end
30
29
 
30
+ class Action
31
+ attr_accessor :route, :options, :block
32
+ def initialize(route, options, block)
33
+ @route, @options, @block = route, options, block
34
+ end
35
+
36
+ def method
37
+ self.class.to_s.downcase.to_sym
38
+ end
39
+ end
40
+
41
+ class Get < Action; end
31
42
 
32
43
  class ResourceRouter
33
44
  attr_accessor :routes
34
-
45
+
46
+ def logger
47
+ @@logger ||= Logger.new(STDOUT)
48
+ end
49
+
50
+ def logger=(val)
51
+ @@logger = val
52
+ end
53
+
35
54
  def initialize(parent_resources=[], before_all=[], after_all=[])
36
55
  @current_resource = parent_resources.pop
37
56
  @parent_resources = parent_resources
@@ -51,7 +70,7 @@ module Bebop
51
70
  end
52
71
 
53
72
  def delete(route, options={}, &block)
54
- add_route(:delete, route, options, block)
73
+ add_route(:delete, route, options, block)
55
74
  end
56
75
 
57
76
  def head(route, options={}, &block)
@@ -106,11 +125,10 @@ module Bebop
106
125
  def print
107
126
  #TODO 6! 6! Block parameters, Ah Ah Ah! -> probably need route objects
108
127
  @routes.each do |method, route, options, block, helper, identifier|
109
- puts "#{route}"
110
- puts " method: #{method.to_s.upcase}"
111
- puts " helper: #{helper}" if helper
112
- puts " identifier: #{identifier}" if identifier
113
- puts
128
+ logger.info "#{route}"
129
+ logger.info " method: #{method.to_s.upcase}"
130
+ logger.info " helper: #{helper}" if helper
131
+ logger.info " identifier: #{identifier} " if identifier
114
132
  end
115
133
  end
116
134
 
@@ -131,7 +149,7 @@ module Bebop
131
149
  end
132
150
 
133
151
  def add_route(method, route, options, block)
134
- identifier =options[:identifier]
152
+ identifier = options[:identifier]
135
153
  route = append_to_path(route)
136
154
  block = add_filters_to_block(block, identifier, method)
137
155
  helper = route_helper(identifier)
@@ -147,7 +147,10 @@ describe Bebop do
147
147
  last_response.body.should == 'success'
148
148
  end
149
149
 
150
- it "should produce correct routes for more than 2 levels of nesting"
150
+ it "should produce correct routes for more than 2 levels of nesting" do
151
+ get '/foos/1/bars/2/bazs'
152
+ last_response.body.should match(/#{BEFORE_ALL_2}/)
153
+ end
151
154
 
152
155
  BEFORE_BARS = '__before_bars__'
153
156
  BEFORE_UPDATE = '__before_update__'
@@ -193,6 +196,10 @@ describe Bebop do
193
196
  bar.destroy { "#{@all2}#{@all}#{@update}#{@bars}" }
194
197
 
195
198
  bar.show { "show #{params[:foo_id]} #{params[:bar_id]}" }
199
+
200
+ bar.resource :bazs do |baz|
201
+ baz.index { @all2 }
202
+ end
196
203
  end
197
204
 
198
205
  foo.get('/do/something') { 'success' }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bebop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Bender