app-routes 0.1.16 → 0.1.17

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e5c95468c4c0a0c165a6c7bfc8c7eb1365d20d0c
4
- data.tar.gz: e5c58059a05aef22ee78d3e807bdde3465e0d9b8
3
+ metadata.gz: 263ef4b0b1ec428769f8522b2d7d7ac47717a11a
4
+ data.tar.gz: be92747bc18486819eb734c0bbfdad5e5c3de7e2
5
5
  SHA512:
6
- metadata.gz: 31e18397dfd7fa8a8974da56be8e23aeff1c23c76e0305b6a93c433978edda961088c2f9c77f2a93ecb1f8b0713267477f929e13827620a99ec976171b90d7d9
7
- data.tar.gz: 529c71a38202e4c5e18515e3d065cce97134b977e0ec1d0e36668d47a0ce61f8761aa2f1b6ff6b650816c11cd5869e3fca2cc83e5fc12b58e153097f5b51d196
6
+ metadata.gz: a0ac549510f98d476e71ec029d1d2a1affa4839d033eb705124205a1d18d79c9b442c03c03f7c12c81d7ac00d68b012854f2454749fed788237686c74085fc1d
7
+ data.tar.gz: 42585afdab950e182eba995048f59a2292555ae4a3d8dfbaa85568ea055628680955aaeb0b54af1db24c9b5a59c69c81562497e3ced2e798a8580d70983291bf
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -2,24 +2,28 @@
2
2
 
3
3
  # file: app-routes.rb
4
4
 
5
+
5
6
  module AppRoutes
6
7
 
7
8
  attr_accessor :routes
8
9
 
9
10
  def initialize(logfile='/tmp/app-routes.log')
10
- @routes = {}
11
+ @get_routes, @post_routes = {}, {}
11
12
  @params = {}
12
13
  end
13
14
 
14
- def run_route(request)
15
+ def run_route(request, request_method='GET')
15
16
 
16
17
  result = nil
17
18
 
18
- routes = @routes
19
-
20
- return unless routes
19
+ return unless @get_routes or @post_routes
21
20
 
22
- route = routes.detect {|key, block| request.match(key) }
21
+ route, routes = case request_method
22
+ when 'GET'
23
+ [@get_routes.detect {|key, block| request.match(key) }, @get_routes]
24
+ when 'POST'
25
+ [@post_routes.detect {|key, block| request.match(key) }, @post_routes]
26
+ end
23
27
 
24
28
  if route then
25
29
  key, block = route
@@ -54,19 +58,34 @@ module AppRoutes
54
58
  send (methodx[arg.class.to_s.to_sym]), arg, &block
55
59
  end
56
60
 
57
- def add_route(arg)
58
- get(arg) {yield(@params)}
61
+ def post(arg,&block)
62
+ methodx = {String: :string_post, Regexp: :regex_post}
63
+ send (methodx[arg.class.to_s.to_sym]), arg, &block
64
+ end
65
+
66
+ def add_route(arg, request_method='GET')
67
+ name = request_method == 'GET' ? :get : :post
68
+ method(name).call(arg) {yield(@params)}
59
69
  end
60
70
 
61
71
  private
62
72
 
63
73
  def string_get(raw_s, &block)
64
74
  s = "^%s$" % raw_s.gsub(/\:[\w-]+/,'([\w-]+)').gsub(/\/\*/,'(.*)')
65
- @routes[Regexp.new s] = {s: raw_s, block: block}
75
+ @get_routes[Regexp.new s] = {s: raw_s, block: block}
66
76
  end
67
77
 
68
78
  def regex_get(r, &block)
69
- @routes[r] = {block: block}
79
+ @get_routes[r] = {block: block}
80
+ end
81
+
82
+ def string_post(raw_s, &block)
83
+ s = "^%s$" % raw_s.gsub(/\:[\w-]+/,'([\w-]+)').gsub(/\/\*/,'(.*)')
84
+ @post_routes[Regexp.new s] = {s: raw_s, block: block}
85
+ end
86
+
87
+ def regex_post(r, &block)
88
+ @post_routes[r] = {block: block}
70
89
  end
71
90
 
72
91
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: app-routes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.16
4
+ version: 0.1.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -10,26 +10,28 @@ bindir: bin
10
10
  cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
- MIIDRDCCAiygAwIBAgIBADANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
13
+ MIIDljCCAn6gAwIBAgI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UvyNSgZvU9UK6PX
31
+ CZGra4Y0S+K0fINIK2l1MYyjxOsO6VCvVCdUf17d5L2tMEIeJfzPaqOldIR0lA40
32
+ kANeVHhqH+wo9g==
31
33
  -----END CERTIFICATE-----
32
- date: 2013-12-24 00:00:00.000000000 Z
34
+ date: 2014-02-15 00:00:00.000000000 Z
33
35
  dependencies: []
34
36
  description:
35
37
  email: james@r0bertson.co.uk
@@ -48,17 +50,17 @@ require_paths:
48
50
  - lib
49
51
  required_ruby_version: !ruby/object:Gem::Requirement
50
52
  requirements:
51
- - - ">="
53
+ - - '>='
52
54
  - !ruby/object:Gem::Version
53
55
  version: '0'
54
56
  required_rubygems_version: !ruby/object:Gem::Requirement
55
57
  requirements:
56
- - - ">="
58
+ - - '>='
57
59
  - !ruby/object:Gem::Version
58
60
  version: '0'
59
61
  requirements: []
60
62
  rubyforge_project:
61
- rubygems_version: 2.0.3
63
+ rubygems_version: 2.0.14
62
64
  signing_key:
63
65
  specification_version: 4
64
66
  summary: app-routes
metadata.gz.sig CHANGED
Binary file