slug-engine 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/lib/slug/filter.rb +15 -13
  2. data/lib/slug/version.rb +1 -1
  3. metadata +4 -4
@@ -1,11 +1,12 @@
1
- # This middleware is necessary so that the engine can abstain from processing
2
- # requests where no such slug exists. If this behavior were done in a
3
- # controller, Rails would heavily mutate the request object and no additional
4
- # controllers would have much luck processing the request. Specifically, the
5
- # named parameters for the route are cached on the request, and downstream
6
- # controllers would get the wrong params hash.
7
-
8
1
  module Slug
2
+
3
+ # This middleware is necessary so that the engine can abstain from processing
4
+ # requests where no such slug exists. If this behavior were done in a
5
+ # controller, Rails would heavily mutate the request object and no additional
6
+ # controllers would have much luck processing the request. Specifically, the
7
+ # named parameters for the route are cached on the request, and downstream
8
+ # controllers would get the wrong params hash.
9
+
9
10
  class Filter
10
11
 
11
12
  def initialize(app)
@@ -14,18 +15,19 @@ module Slug
14
15
 
15
16
  def call(env)
16
17
  # if a matching slug exists in the database, allow engine to process it
17
- if Permalink.where('slug = ?', slug(env)).exists?
18
+ if Permalink.where('slug = ?', slug(env['PATH_INFO'])).exists?
19
+ # slug found, allow request to continue to controller
18
20
  @app.call(env)
19
- else # force engine to abstain from processing this request
21
+ else
22
+ # no slug matched, abstain from handling request
20
23
  [404, {"X-Cascade" => "pass"}, ["no such slug exists"]]
21
24
  end
22
25
  end
23
26
 
24
27
  # Extract the :slug value from the raw request
25
- def slug(env)
26
- slug = env['PATH_INFO']
27
- slug = slug.slice(1..-1) if slug[0] == 47 # has a leading '/'
28
- slug
28
+ def slug(path)
29
+ path.match(/^(?:\/)?([^.]+)(?:\..*)?/)[1]
29
30
  end
31
+
30
32
  end
31
33
  end
@@ -1,3 +1,3 @@
1
1
  module Slug
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slug-engine
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jarrod Carlson
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-11-14 00:00:00 Z
18
+ date: 2011-12-08 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  type: :runtime