Skip to content
This repository has been archived by the owner on Feb 26, 2018. It is now read-only.

Commit

Permalink
Merge 4b53f72 into 366533c
Browse files Browse the repository at this point in the history
  • Loading branch information
indrekj committed May 27, 2013
2 parents 366533c + 4b53f72 commit 6ff032f
Show file tree
Hide file tree
Showing 38 changed files with 636 additions and 306 deletions.
4 changes: 0 additions & 4 deletions .travis.yml
Expand Up @@ -29,7 +29,3 @@ matrix:
env: JRUBY_OPTS="$JRUBY_OPTS --debug"
- rvm: jruby-head
env: JRUBY_OPTS="$JRUBY_OPTS --debug"
allow_failures:
# mutant fails
- rvm: 1.9.3
- rvm: rbx-19mode
25 changes: 11 additions & 14 deletions Gemfile.devtools
@@ -1,45 +1,42 @@
# encoding: utf-8

group :development do
gem 'rake', '~> 10.0.3'
gem 'rake', '~> 10.0.4'
gem 'rspec', '~> 2.13.0'
gem 'yard', '~> 0.8.5'
gem 'yard', '~> 0.8.6.1'
end

group :yard do
gem 'kramdown', '~> 1.0.1'
end

group :guard do
gem 'guard', '~> 1.6.2'
gem 'guard', '~> 1.8.0'
gem 'guard-bundler', '~> 1.0.0'
gem 'guard-rspec', '~> 2.5.1'
gem 'guard-rspec', '~> 2.5.4'

# file system change event handling
gem 'listen', '~> 1.0.2'
gem 'rb-fchange', '~> 0.0.6', :require => false
gem 'rb-fsevent', '~> 0.9.3', :require => false
gem 'rb-inotify', '~> 0.9.0', :require => false

gem 'listen', '~> 0.7.3'

# notification handling
gem 'libnotify', '~> 0.8.0', :require => false
gem 'rb-notifu', '~> 0.0.4', :require => false
gem 'terminal-notifier-guard', '~> 1.5.3', :require => false
end

group :metrics do
gem 'backports', '~> 3.1', '>= 3.1.1'
gem 'coveralls', '~> 0.6.2'
gem 'flay', '~> 2.1.0'
gem 'flog', '~> 3.2.2'
gem 'backports', '~> 3.3', '>= 3.3.0'
gem 'coveralls', '~> 0.6.6'
gem 'flay', '~> 2.2.0'
gem 'flog', '~> 4.0.0'
gem 'reek', '~> 1.3.1', :git => 'https://github.com/troessner/reek.git'
gem 'metric_fu-roodi', '~> 2.2.1'
gem 'simplecov', '~> 0.7.1'
gem 'yardstick', '~> 0.9.4'
gem 'yardstick', '~> 0.9.6'

platforms :ruby_18, :ruby_19 do
# this indirectly depends on ffi which does not build on ruby-head
platforms :ruby_19 do
gem 'yard-spellcheck', '~> 0.1.5'
end

Expand Down
4 changes: 2 additions & 2 deletions config/flay.yml
@@ -1,3 +1,3 @@
---
threshold: 14
total_score: 71
threshold: 12
total_score: 69
2 changes: 1 addition & 1 deletion config/flog.yml
@@ -1,2 +1,2 @@
---
threshold: 16.7
threshold: 13
129 changes: 72 additions & 57 deletions config/reek.yml
@@ -1,95 +1,110 @@
---
UncommunicativeParameterName:
accept: []
exclude: []
Attribute:
enabled: true
exclude:
- Inflecto::Inflections
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
overrides: {}
FeatureEnvy:
exclude:
- Inflecto::Inflections#irregular
- Inflecto::Inflections
max_copies: 2
min_clump_size: 2
DuplicateMethodCall:
enabled: true
ClassVariable:
exclude: []
exclude:
- Inflecto#self.camelize
max_calls: 1
allow_calls: []
FeatureEnvy:
enabled: true
BooleanParameter:
exclude: []
enabled: true
IrresponsibleModule:
exclude: []
enabled: true
UncommunicativeModuleName:
accept: []
exclude: []
LongParameterList:
enabled: true
reject:
- !ruby/regexp /^.$/
- !ruby/regexp /[0-9]$/
exclude:
- Inflecto::Inflections#add_irregular
- Inflecto::Inflections#rule
max_params: 2
overrides:
initialize:
max_params: 3
LongYieldList:
enabled: true
exclude: []
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
- Inflecto::Inflections
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: 5
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
72 changes: 39 additions & 33 deletions lib/inflecto.rb
Expand Up @@ -23,7 +23,7 @@ module Inflecto
# @api public
#
def self.camelize(input)
input.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
input.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
end

# Convert input to underscored, lowercase string
Expand All @@ -41,11 +41,11 @@ def self.camelize(input)
# @api public
#
def self.underscore(input)
word = input.to_s.dup
word = input.dup
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
Expand Down Expand Up @@ -79,7 +79,7 @@ def self.dasherize(input)
# @api public
#
def self.demodulize(input)
input.to_s.gsub(/^.*::/, '')
input.gsub(/^.*::/, '')
end

# Creates a foreign key name
Expand Down Expand Up @@ -144,10 +144,12 @@ def self.constantize(input)
# @api private
#
def self.ordinalize(number)
if (11..13).include?(number.to_i % 100)
abs_value = number.abs

if (11..13).include?(abs_value % 100)
"#{number}th"
else
case number.to_i % 10
case abs_value % 10
when 1; "#{number}st"
when 2; "#{number}nd"
when 3; "#{number}rd"
Expand All @@ -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
Expand All @@ -193,14 +192,8 @@ def self.inflections
# @api public
#
def self.pluralize(word)
result = word.to_s.dup

if result.empty? || inflections.uncountables.include?(result.downcase)
result
else
inflections.plurals.each { |(rule, replacement)| break if result.gsub!(rule, replacement) }
result
end
return word if uncountable?(word)
inflections.plurals.apply_to(word)
end

# Convert word to singular
Expand All @@ -220,14 +213,8 @@ def self.pluralize(word)
# @api public
#
def self.singularize(word)
result = word.to_s.dup

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
return word if uncountable?(word)
inflections.singulars.apply_to(word)
end

# Humanize string
Expand All @@ -247,13 +234,13 @@ def self.singularize(word)
# @api private
#
def self.humanize(input)
result = input.to_s.dup

inflections.humans.each { |(rule, replacement)| break if result.gsub!(rule, replacement) }
result.gsub(/_id$/, "").gsub(/_/, " ").capitalize
result = inflections.humans.apply_to(input)
result.gsub!(/_id$/, "")
result.gsub!(/_/, " ")
result.capitalize!
result
end


# Tabelize input string
#
# @param [String] input
Expand Down Expand Up @@ -296,10 +283,29 @@ def self.tableize(input)
#
def self.classify(table_name)
# strip out any leading schema name
camelize(singularize(table_name.to_s.sub(/.*\./, '')))
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/rules_collection'
require 'inflecto/inflections'
require 'inflecto/defaults'

0 comments on commit 6ff032f

Please sign in to comment.