friendly_routes 0.2.0 → 0.3.0

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: 7de0ba5374e04ea6b36c94db8b69f578625d93e1
4
- data.tar.gz: 637009a6c665bb90b54aa4256accab74d61aa9fa
3
+ metadata.gz: 77ed12df2420528a82f7ed13566099b1d72a95e8
4
+ data.tar.gz: 24b3222a6adc594631e82b6000773b4f373daac6
5
5
  SHA512:
6
- metadata.gz: c5e2aa090122f1eecdef2e61ddeb63fb9dccb8a7c75b802a39e07f9ff137fbb5f991a8e66fa44092387aa39dbce6a737ac985eb71d77d61f48d99f3146411f84
7
- data.tar.gz: 919abe796d939ef71af29b6b907f9e16ba79f4c77ec5d309ea42588df2084f4793b0217b2cff4abd34630bc021c53046fc1bf43f8351e2882d2766d37a89bf16
6
+ metadata.gz: 95ab4a5e21c0d7f81b3f3cf3bbb137b776bee0aa59eb8a1f2c381e466b2bddf9a5157556437cadb565316493bd293f0c8da9da9aef6ae53c22514bb0b40548e7
7
+ data.tar.gz: 6fcc0e2a5ad78d02ce560233d2687d5116d8ca840af4d1684ef638ee5c16602584d5e2a8516f36e0a2c8dcc83ec76f578acb462306cba4cc2fe85d6cf59ffd94
data/README.md CHANGED
@@ -34,10 +34,11 @@ dummies_route.params = [free, category]
34
34
 
35
35
  friendly_url_for dummies_route, :get # '/:free/:category'
36
36
 
37
- second_dummies_route = FriendlyRoutes::Route.new(:get, '/', controller: :dummies, action: :index)
37
+ second_dummies_route = FriendlyRoutes::Route.new(controller: :dummies, action: :index)
38
38
  dummies_route.params = [free, 'categories', category]
39
39
 
40
- friendly_url_for dummies_route, :get # '/:free/categories/:category'
40
+ friendly_url_for dummies_route, :get, '/' # '/:free/categories/:category'
41
+ friendly_url_for dummies_route, :get, '/hello/' # '/hello/:free/categories/:category'
41
42
 
42
43
  # app/controllers/dummies_controller.rb
43
44
  class DummiesController < ApplicationController
@@ -2,12 +2,12 @@
2
2
 
3
3
  module FriendlyRoutes
4
4
  module Dispatcher
5
- def friendly_url_for(route, method, as: '')
5
+ def friendly_url_for(route, method, path, as: '', controller: '', action: '')
6
6
  public_send(
7
7
  method,
8
- route.path,
9
- controller: route.controller,
10
- action: route.action,
8
+ path + route.path,
9
+ controller: controller,
10
+ action: action,
11
11
  friendly_route: route,
12
12
  constraints: route.constraints,
13
13
  as: as
@@ -2,18 +2,15 @@
2
2
 
3
3
  module FriendlyRoutes
4
4
  class Route
5
- attr_accessor :method, :controller, :action, :params, :prefix
5
+ attr_accessor :method, :params, :prefix
6
6
 
7
- def initialize(path, controller: nil, action: nil, prefix: 'friendly_routes')
8
- @original_path = path
9
- @controller = controller
10
- @action = action
7
+ def initialize(prefix: 'friendly_routes')
11
8
  @params = []
12
9
  @prefix = prefix
13
10
  end
14
11
 
15
12
  def path
16
- @original_path + FriendlyRoutes::PrefixedParams.new(@params, @prefix).call
13
+ FriendlyRoutes::PrefixedParams.new(@params, @prefix).call
17
14
  end
18
15
 
19
16
  def constraints
@@ -21,7 +21,7 @@ module FriendlyRoutes
21
21
  value = @params[prefixed_name]
22
22
  return unless value
23
23
  @params[param.name] = param.parse(value)
24
- @params.delete(prefixed_name)
24
+ @params.delete(prefixed_name) unless param.name == prefixed_name
25
25
  end
26
26
  end
27
27
  end
@@ -8,7 +8,7 @@ module FriendlyRoutes
8
8
  end
9
9
 
10
10
  def call
11
- "#{@prefix}_#{@param}"
11
+ @prefix ? "#{@prefix}_#{@param}" : @param
12
12
  end
13
13
  end
14
14
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FriendlyRoutes
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: friendly_routes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roman Gritsay
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-04 00:00:00.000000000 Z
11
+ date: 2016-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails