route_translator 4.2.2 → 4.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fed95d7d2bb5c6760f755a65866d1bb712af7493
4
- data.tar.gz: a68d7427215b389db7a8f7b327df93559808c26e
3
+ metadata.gz: 0245ec3dc888fe4075acdc5b7f75a83abc484315
4
+ data.tar.gz: 830fe48ec660d44d6f41611addc896c917fc6e05
5
5
  SHA512:
6
- metadata.gz: c75f272a76d785a14832ff9512f70fcb7e9ee9f8865705f3f47c30cd1e068c60dbf23f903ce10a22865c5de95d78ca7f72c50ec54b331602eefc8b61b154e853
7
- data.tar.gz: 5d625add24e8f730a10bc0122641c1b1c874e4c776477daaf6feb0e0ccf3cb81749de3f4dad568e28c81358cb9e592c0993de5aed216096322b551d687a78441
6
+ metadata.gz: a3887741389738e173cd52b317bc81f463c42c640ae255d4f85e48dcb4fccf17ee06baa6543a265a9d35dbe9848fffb24fdd97d4f7e7ac3854a465e678f16db3
7
+ data.tar.gz: 0411af88304f09a2005960c0d24699d50a8e2a5a24b1b55895336ca0ef09790082749bd7aacbeca46e059d6515e74fe3a37dc390fc5a95c9e2374688f7b25356
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.2.3 (2016-01-15)
4
+
5
+ * Minor tweaks
6
+
3
7
  ## 4.2.2 (2015-12-16)
4
8
 
5
9
  * Fix: native path generation with host_locale (#95)
@@ -7,7 +7,7 @@ require File.expand_path('../route_translator/host', __FILE__)
7
7
  module RouteTranslator
8
8
  extend RouteTranslator::Host
9
9
 
10
- TRANSLATABLE_SEGMENT = /^([-_a-zA-Z0-9]+)(\()?/.freeze
10
+ TRANSLATABLE_SEGMENT = /^([-_a-zA-Z0-9]+)(\()?/
11
11
 
12
12
  Configuration = Struct.new(:force_locale, :hide_locale,
13
13
  :generate_unlocalized_routes, :locale_param_key,
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'action_dispatch'
2
3
 
3
4
  module ActionDispatch
@@ -9,46 +10,31 @@ module ActionDispatch
9
10
  @localized = false
10
11
  end
11
12
 
12
- if instance_methods.map(&:to_s).include?('add_route'.freeze)
13
- def add_route(action, options) # :nodoc:
14
- path = path_for_action(action, options.delete(:path))
13
+ def add_route(action, options) # :nodoc:
14
+ path = path_for_action(action, options.delete(:path))
15
15
 
16
- if action.to_s =~ %r{^[\w\/]+$}.freeze
17
- options[:action] ||= action unless action.to_s.include?('/'.freeze)
18
- else
19
- action = nil
20
- end
21
-
22
- if !options.fetch(:as, true)
23
- options.delete(:as)
24
- else
25
- options[:as] = name_for_action(options[:as], action)
26
- end
16
+ if action.to_s =~ %r{^[\w\/]+$}
17
+ options[:action] ||= action unless action.to_s.include?('/'.freeze)
18
+ else
19
+ action = nil
20
+ end
27
21
 
28
- begin
29
- mapping = Mapping.new(@set, @scope, path, options)
30
- rescue ArgumentError
31
- mapping = Mapping.build(@scope, @set, URI.parser.escape(path), options.delete(:as), options)
32
- end
22
+ if !options.fetch(:as, true)
23
+ options.delete(:as)
24
+ else
25
+ options[:as] = name_for_action(options[:as], action)
26
+ end
33
27
 
34
- if @localized
35
- @set.add_localized_route(*mapping.to_route)
36
- else
37
- @set.add_route(*mapping.to_route)
38
- end
28
+ begin
29
+ mapping = Mapping.new(@set, @scope, path, options)
30
+ rescue ArgumentError
31
+ mapping = Mapping.build(@scope, @set, URI.parser.escape(path), options.delete(:as), options)
39
32
  end
40
- else
41
- module Base
42
- def match(path, options = nil)
43
- mapping = Mapping.new(@set, @scope, path, options || {})
44
- app, conditions, requirements, defaults, as, anchor = mapping.to_route
45
- if @localized
46
- @set.add_localized_route(app, conditions, requirements, defaults, as, anchor)
47
- else
48
- @set.add_route(app, conditions, requirements, defaults, as, anchor)
49
- end
50
- self
51
- end
33
+
34
+ if @localized
35
+ @set.add_localized_route(*mapping.to_route)
36
+ else
37
+ @set.add_route(*mapping.to_route)
52
38
  end
53
39
  end
54
40
  end
@@ -7,6 +7,12 @@ module ActionDispatch
7
7
  RouteTranslator::Translator.translations_for(app, conditions, requirements, defaults, as, anchor, self) do |*translated_args|
8
8
  add_route(*translated_args)
9
9
  end
10
+
11
+ if RouteTranslator.config.generate_unnamed_unlocalized_routes
12
+ add_route app, conditions, requirements, defaults, nil, anchor
13
+ elsif RouteTranslator.config.generate_unlocalized_routes
14
+ add_route app, conditions, requirements, defaults, as, anchor
15
+ end
10
16
  end
11
17
  end
12
18
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module RouteTranslator
2
3
  module Translator
3
4
  # Add standard route helpers for default locale e.g.
@@ -58,15 +59,8 @@ module RouteTranslator
58
59
  new_route_name = nil if new_route_name && route_set.named_routes.routes[new_route_name.to_sym] # TODO: Investigate this :(
59
60
  block.call(app, new_conditions, new_requirements, new_defaults, new_route_name, anchor)
60
61
  end
61
- if RouteTranslator.config.generate_unnamed_unlocalized_routes
62
- block.call(app, conditions, requirements, defaults, nil, anchor)
63
- elsif RouteTranslator.config.generate_unlocalized_routes
64
- block.call(app, conditions, requirements, defaults, route_name, anchor)
65
- end
66
62
  end
67
63
 
68
- private
69
-
70
64
  def self.available_locales
71
65
  available_locales = config_locales || I18n.available_locales.dup
72
66
  available_locales.push(*RouteTranslator.native_locales) if RouteTranslator.native_locales.present?
@@ -134,7 +128,7 @@ module RouteTranslator
134
128
  end
135
129
 
136
130
  def self.translate_string(str, locale)
137
- locale = "#{locale}".gsub('native_', '')
131
+ locale = locale.to_s.gsub('native_', '')
138
132
  opts = { scope: :routes, locale: locale }
139
133
  if RouteTranslator.config.disable_fallback && locale.to_s != I18n.default_locale.to_s
140
134
  opts[:fallback] = true
@@ -146,7 +140,7 @@ module RouteTranslator
146
140
  end
147
141
 
148
142
  def self.locale_param_present?(path)
149
- !(path.split('/').detect { |segment| segment.to_s == ":#{RouteTranslator.locale_param_key}" }.nil?)
143
+ !path.split('/').detect { |segment| segment.to_s == ":#{RouteTranslator.locale_param_key}" }.nil?
150
144
  end
151
145
 
152
146
  def self.host_locales_option?
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module RouteTranslator
2
- VERSION = '4.2.2'
3
+ VERSION = '4.2.3'.freeze
3
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: route_translator
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.2
4
+ version: 4.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Raul Murciano
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-12-16 00:00:00.000000000 Z
12
+ date: 2016-01-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -125,14 +125,14 @@ dependencies:
125
125
  requirements:
126
126
  - - "~>"
127
127
  - !ruby/object:Gem::Version
128
- version: '0.35'
128
+ version: 0.36.0
129
129
  type: :development
130
130
  prerelease: false
131
131
  version_requirements: !ruby/object:Gem::Requirement
132
132
  requirements:
133
133
  - - "~>"
134
134
  - !ruby/object:Gem::Version
135
- version: '0.35'
135
+ version: 0.36.0
136
136
  - !ruby/object:Gem::Dependency
137
137
  name: simplecov
138
138
  requirement: !ruby/object:Gem::Requirement
@@ -185,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
185
185
  version: '0'
186
186
  requirements: []
187
187
  rubyforge_project:
188
- rubygems_version: 2.4.5.1
188
+ rubygems_version: 2.4.3
189
189
  signing_key:
190
190
  specification_version: 4
191
191
  summary: Translate your Rails routes in a simple manner