Skip to content

Commit

Permalink
Improve PathTranslator
Browse files Browse the repository at this point in the history
  • Loading branch information
tagliala committed Mar 3, 2016
1 parent 8a554a2 commit 8b92fa8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ AllCops:
- 'vendor/bundle/**/*'

Metrics/AbcSize:
Max: 33.14 # TODO: Lower to 15
Max: 23.35 # TODO: Lower to 15
Exclude:
- 'test/**/*'

Expand Down
14 changes: 8 additions & 6 deletions lib/route_translator/translator/path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@ class << self

def display_locale?(locale)
!RouteTranslator.config.hide_locale && !RouteTranslator.native_locale?(locale) &&
(!default_locale?(locale) ||
RouteTranslator.config.force_locale ||
RouteTranslator.config.generate_unlocalized_routes ||
RouteTranslator.config.generate_unnamed_unlocalized_routes)
(!default_locale?(locale) || config_requires_locale?)
end

def config_requires_locale?
config = RouteTranslator.config
(config.force_locale || config.generate_unlocalized_routes || config.generate_unnamed_unlocalized_routes).present?
end

def default_locale?(locale)
I18n.default_locale.to_sym == locale.to_sym
locale.to_sym == I18n.default_locale.to_sym
end

def locale_param_present?(path)
!path.split('/').detect { |segment| segment.to_s == ":#{RouteTranslator.locale_param_key}" }.nil?
path.split('/').include? ":#{RouteTranslator.locale_param_key}"
end
end

Expand Down

0 comments on commit 8b92fa8

Please sign in to comment.