Permalink
Browse files

Fix some reek warnings

  • Loading branch information...
1 parent 0f0c74b commit 3d8ab069fd77e61a64703addf219396b5265dd37 @indrekj indrekj committed May 27, 2013
Showing with 99 additions and 78 deletions.
  1. +66 −56 config/reek.yml
  2. +33 −22 lib/inflecto.rb
View
@@ -1,95 +1,105 @@
---
-UncommunicativeParameterName:
- accept: []
+Attribute:
+ enabled: true
exclude: []
+BooleanParameter:
enabled: true
- reject:
- - !ruby/regexp /^.$/
- - !ruby/regexp /[0-9]$/
- - !ruby/regexp /[A-Z]/
-LargeClass:
- max_methods: 14
exclude: []
+ClassVariable:
enabled: true
- max_instance_variables: 8
-UncommunicativeMethodName:
- accept: []
exclude: []
+ControlParameter:
enabled: true
- reject:
- - !ruby/regexp /^[a-z]$/
- - !ruby/regexp /[0-9]$/
- - !ruby/regexp /[A-Z]/
-LongParameterList:
- max_params: 3
exclude: []
+DataClump:
+ enabled: true
+ exclude: []
+ max_copies: 2
+ min_clump_size: 2
+DuplicateMethodCall:
enabled: true
- overrides: {}
-FeatureEnvy:
exclude:
- - Inflecto::Inflections#irregular
+ - Inflecto#self.camelize
+ max_calls: 1
+ allow_calls: []
+FeatureEnvy:
enabled: true
-ClassVariable:
exclude: []
+IrresponsibleModule:
enabled: true
-BooleanParameter:
exclude: []
+LongParameterList:
enabled: true
-IrresponsibleModule:
exclude: []
+ max_params: 2
+ overrides:
+ initialize:
+ max_params: 3
+LongYieldList:
enabled: true
-UncommunicativeModuleName:
- accept: []
exclude: []
- enabled: true
- reject:
- - !ruby/regexp /^.$/
- - !ruby/regexp /[0-9]$/
+ max_params: 2
NestedIterators:
+ enabled: true
+ exclude: []
+ max_allowed_nesting: 1
ignore_iterators: []
+NilCheck:
+ enabled: true
exclude: []
+RepeatedConditional:
enabled: true
- max_allowed_nesting: 2
-LongMethod:
- max_statements: 8
- exclude:
- - Inflecto::Inflections#irregular
+ exclude: []
+ max_ifs: 1
+TooManyInstanceVariables:
enabled: true
-Duplication:
- allow_calls: []
- exclude:
- - Inflecto::Inflections#irregular
+ exclude: []
+ max_instance_variables: 3
+TooManyMethods:
enabled: true
- max_calls: 2
-UtilityFunction:
- max_helper_calls: 1
exclude: []
+ max_methods: 10
+TooManyStatements:
+ enabled: true
+ exclude:
+ - each
+ - Inflecto#self.underscore
+ max_statements: 6
+UncommunicativeMethodName:
enabled: true
-Attribute:
exclude: []
- enabled: false
-UncommunicativeVariableName:
+ reject:
+ - !ruby/regexp /^[a-z]$/
+ - !ruby/regexp /[0-9]$/
+ - !ruby/regexp /[A-Z]/
accept: []
+UncommunicativeModuleName:
+ enabled: true
exclude: []
+ reject:
+ - !ruby/regexp /^.$/
+ - !ruby/regexp /[0-9]$/
+ accept: []
+UncommunicativeParameterName:
enabled: true
+ exclude: []
reject:
- !ruby/regexp /^.$/
- !ruby/regexp /[0-9]$/
- !ruby/regexp /[A-Z]/
-SimulatedPolymorphism:
- exclude: []
- enabled: true
- max_ifs: 2
-DataClump:
- exclude:
- - Inflecto::Inflections
+ accept: []
+UncommunicativeVariableName:
enabled: true
- max_copies: 2
- min_clump_size: 2
-ControlCouple:
exclude: []
+ reject:
+ - !ruby/regexp /^.$/
+ - !ruby/regexp /[0-9]$/
+ - !ruby/regexp /[A-Z]/
+ accept: []
+UnusedParameters:
enabled: true
-LongYieldList:
- max_params: 1
exclude: []
+UtilityFunction:
enabled: true
+ exclude: []
+ max_helper_calls: 0
View
@@ -45,7 +45,7 @@ def self.underscore(input)
word.gsub!(/::/, '/')
word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
- word.tr!("-", "_")
+ word.tr!('-', '_')
word.downcase!
word
end
@@ -144,10 +144,12 @@ def self.constantize(input)
# @api private
#
def self.ordinalize(number)
- if (11..13).include?(number.abs % 100)
+ abs_value = number.abs
+
+ if (11..13).include?(abs_value % 100)
"#{number}th"
else
- case number.abs % 10
+ case abs_value % 10
when 1; "#{number}st"
when 2; "#{number}nd"
when 3; "#{number}rd"
@@ -169,11 +171,8 @@ def self.ordinalize(number)
# @api public
#
def self.inflections
- if block_given?
- yield Inflections.instance
- else
- Inflections.instance
- end
+ instance = Inflections.instance
+ block_given? ? yield(instance) : instance
end
# Convert input word string to plural
@@ -193,14 +192,11 @@ def self.inflections
# @api public
#
def self.pluralize(word)
- result = word.dup
+ return word if uncountable?(word)
- if result.empty? || inflections.uncountables.include?(result.downcase)
- result
- else
- inflections.plurals.each { |rule, replacement| break if result.gsub!(rule, replacement) }
- result
- end
+ result = word.dup
+ inflections.plurals.each { |rule, replacement| break if result.gsub!(rule, replacement) }
+ result
end
# Convert word to singular
@@ -220,14 +216,11 @@ def self.pluralize(word)
# @api public
#
def self.singularize(word)
- result = word.dup
+ return word if uncountable?(word)
- if inflections.uncountables.any? { |inflection| result =~ /\b(#{inflection})\Z/i }
- result
- else
- inflections.singulars.each { |rule, replacement| break if result.gsub!(rule, replacement) }
- result
- end
+ result = word.dup
+ inflections.singulars.each { |rule, replacement| break if result.gsub!(rule, replacement) }
+ result
end
# Humanize string
@@ -301,6 +294,24 @@ def self.classify(table_name)
camelize(singularize(table_name.sub(/.*\./, '')))
end
+ # Detects uncountable words
+ #
+ # @example
+ #
+ # Inflecto.uncountable?('rice') #=> true
+ # Inflecto.uncountable?('apple') #=> false
+ #
+ # @param [String] word
+ #
+ # @return [Boolean]
+ # true, if word is uncountable
+ #
+ # @api private
+ #
+ def self.uncountable?(word)
+ word.empty? || inflections.uncountables.include?(word.downcase)
+ end
+ private_class_method :uncountable?
end
require 'inflecto/inflections'

0 comments on commit 3d8ab06

Please sign in to comment.