-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #134 from joost/rubocop
Added first RuboCop stuff.
- Loading branch information
Showing
15 changed files
with
267 additions
and
221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
inherit_from: .rubocop_todo.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# This configuration was generated by | ||
# `rubocop --auto-gen-config` | ||
# on 2016-03-12 20:44:43 +0100 using RuboCop version 0.38.0. | ||
# The point is for the user to remove these configuration records | ||
# one by one as the offenses are removed from the code base. | ||
# Note that changes in the inspected code, or installation of new | ||
# versions of RuboCop, may require this file to be generated again. | ||
|
||
# Offense count: 2 | ||
# Configuration parameters: AllowSafeAssignment. | ||
Lint/AssignmentInCondition: | ||
Exclude: | ||
- 'lib/phony_rails.rb' | ||
|
||
# Offense count: 2 | ||
Lint/UnderscorePrefixedVariableName: | ||
Exclude: | ||
- 'lib/phony_rails.rb' | ||
|
||
# Offense count: 4 | ||
Metrics/AbcSize: | ||
Max: 41 | ||
|
||
# Offense count: 3 | ||
Metrics/CyclomaticComplexity: | ||
Max: 21 | ||
|
||
# Offense count: 162 | ||
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes. | ||
# URISchemes: http, https | ||
Metrics/LineLength: | ||
Max: 166 | ||
|
||
# Offense count: 4 | ||
# Configuration parameters: CountComments. | ||
Metrics/MethodLength: | ||
Max: 25 | ||
|
||
# Offense count: 2 | ||
Metrics/PerceivedComplexity: | ||
Max: 23 | ||
|
||
# Offense count: 1 | ||
# Cop supports --auto-correct. | ||
Performance/StartWith: | ||
Exclude: | ||
- 'lib/phony_rails.rb' | ||
|
||
# Offense count: 1 | ||
# Configuration parameters: EnforcedStyle, SupportedStyles. | ||
# SupportedStyles: nested, compact | ||
Style/ClassAndModuleChildren: | ||
Exclude: | ||
- 'lib/phony_rails.rb' | ||
|
||
# Offense count: 7 | ||
Style/Documentation: | ||
Exclude: | ||
- 'spec/**/*' | ||
- 'test/**/*' | ||
- 'lib/phony_rails.rb' | ||
- 'lib/phony_rails/string_extensions.rb' | ||
- 'lib/validators/phony_validator.rb' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
language: ruby | ||
rvm: | ||
- "1.9.3" | ||
- "2.1.3" | ||
- "2.2.1" | ||
- rbx | ||
script: bundle exec rspec spec | ||
- '1.9.3' | ||
- '2.1.3' | ||
- '2.2.1' | ||
script: | ||
- bundle exec rspec spec | ||
- bundle exec rubocop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#!/usr/bin/env rake | ||
require "bundler/gem_tasks" | ||
require 'bundler/gem_tasks' | ||
require 'rspec/core/rake_task' | ||
|
||
RSpec::Core::RakeTask.new(:spec) | ||
task :default => :spec | ||
task default: :spec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,41 @@ | ||
class String | ||
|
||
# Usage: | ||
# "+31 (0)30 1234 123".phony_normalized # => '+31301234123' | ||
# "(0)30 1234 123".phony_normalized # => '301234123' | ||
# "(0)30 1234 123".phony_normalized(country_code: 'NL') # => '301234123' | ||
def phony_normalized(options = {}) | ||
raise ArgumentError, "Expected options to be a Hash, got #{options.inspect}" if not options.is_a?(Hash) | ||
options = options.dup | ||
PhonyRails.normalize_number(self, options) | ||
end | ||
|
||
# Add a method to the String class so we can easily format phone numbers. | ||
# This enables: | ||
# "31612341234".phony_formatted # => '06 12341234' | ||
# "31612341234".phony_formatted(:spaces => '-') # => '06-12341234' | ||
# To first normalize a String use: | ||
# "010-12341234".phony_formatted(:normalize => :NL) | ||
# To return nil when a number is not correct (checked using Phony.plausible?) use | ||
# "010-12341234".phony_formatted(strict: true) | ||
# When an error occurs during conversion it will return the original String. | ||
# To raise an error use: | ||
# "somestring".phone_formatted(raise: true) | ||
def phony_formatted(options = {}) | ||
raise ArgumentError, "Expected options to be a Hash, got #{options.inspect}" if not options.is_a?(Hash) | ||
options = options.dup | ||
normalize_country_code = options.delete(:normalize) | ||
s = (normalize_country_code ? PhonyRails.normalize_number(self, :default_country_code => normalize_country_code.to_s, :add_plus => false) : self.gsub(/\D/, '')) | ||
return if s.blank? | ||
return if options[:strict] && !Phony.plausible?(s) | ||
Phony.format(s, options.reverse_merge(:format => :national)) | ||
rescue | ||
if options[:raise] | ||
raise | ||
else | ||
s | ||
end | ||
end | ||
class String | ||
# Usage: | ||
# "+31 (0)30 1234 123".phony_normalized # => '+31301234123' | ||
# "(0)30 1234 123".phony_normalized # => '301234123' | ||
# "(0)30 1234 123".phony_normalized(country_code: 'NL') # => '301234123' | ||
def phony_normalized(options = {}) | ||
raise ArgumentError, "Expected options to be a Hash, got #{options.inspect}" unless options.is_a?(Hash) | ||
options = options.dup | ||
PhonyRails.normalize_number(self, options) | ||
end | ||
|
||
# The bang method | ||
def phony_formatted!(options = {}) | ||
raise ArgumentError, "The :strict options is only supported in the phony_formatted (non bang) method." if options[:strict] | ||
replace(self.phony_formatted(options)) | ||
end | ||
# Add a method to the String class so we can easily format phone numbers. | ||
# This enables: | ||
# "31612341234".phony_formatted # => '06 12341234' | ||
# "31612341234".phony_formatted(:spaces => '-') # => '06-12341234' | ||
# To first normalize a String use: | ||
# "010-12341234".phony_formatted(:normalize => :NL) | ||
# To return nil when a number is not correct (checked using Phony.plausible?) use | ||
# "010-12341234".phony_formatted(strict: true) | ||
# When an error occurs during conversion it will return the original String. | ||
# To raise an error use: | ||
# "somestring".phone_formatted(raise: true) | ||
def phony_formatted(options = {}) | ||
raise ArgumentError, "Expected options to be a Hash, got #{options.inspect}" unless options.is_a?(Hash) | ||
options = options.dup | ||
normalize_country_code = options.delete(:normalize) | ||
s = (normalize_country_code ? PhonyRails.normalize_number(self, default_country_code: normalize_country_code.to_s, add_plus: false) : gsub(/\D/, '')) | ||
return if s.blank? | ||
return if options[:strict] && !Phony.plausible?(s) | ||
Phony.format(s, options.reverse_merge(format: :national)) | ||
rescue | ||
raise if options[:raise] | ||
s | ||
end | ||
|
||
# The bang method | ||
def phony_formatted!(options = {}) | ||
raise ArgumentError, 'The :strict options is only supported in the phony_formatted (non bang) method.' if options[:strict] | ||
replace(phony_formatted(options)) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module PhonyRails | ||
VERSION = '0.13.0' | ||
VERSION = '0.13.0'.freeze | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,25 +2,25 @@ | |
require File.expand_path('../lib/phony_rails/version', __FILE__) | ||
|
||
Gem::Specification.new do |gem| | ||
gem.authors = ["Joost Hietbrink"] | ||
gem.email = ["[email protected]"] | ||
gem.description = %q{This Gem adds useful methods to your Rails app to validate, display and save phone numbers.} | ||
gem.summary = %q{This Gem adds useful methods to your Rails app to validate, display and save phone numbers.} | ||
gem.homepage = "https://github.com/joost/phony_rails" | ||
gem.authors = ['Joost Hietbrink'] | ||
gem.email = ['[email protected]'] | ||
gem.description = 'This Gem adds useful methods to your Rails app to validate, display and save phone numbers.' | ||
gem.summary = 'This Gem adds useful methods to your Rails app to validate, display and save phone numbers.' | ||
gem.homepage = 'https://github.com/joost/phony_rails' | ||
gem.license = 'MIT' | ||
|
||
gem.files = `git ls-files`.split($\) | ||
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } | ||
gem.files = `git ls-files`.split($OUTPUT_RECORD_SEPARATOR) | ||
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) } | ||
gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) | ||
gem.name = "phony_rails" | ||
gem.require_paths = ["lib"] | ||
gem.name = 'phony_rails' | ||
gem.require_paths = ['lib'] | ||
gem.version = PhonyRails::VERSION | ||
|
||
gem.post_install_message = "PhonyRails v0.10.0 changes the way numbers are stored!" | ||
gem.post_install_message = 'PhonyRails v0.10.0 changes the way numbers are stored!' | ||
gem.post_install_message = "It now adds a '+' to the normalized number when it starts with a country number!" | ||
|
||
gem.add_dependency "phony", '~> 2.12' | ||
gem.add_dependency "activesupport", ">= 3.0" | ||
gem.add_development_dependency "activerecord", ">= 3.0" | ||
gem.add_development_dependency "mongoid", ">= 3.0" | ||
gem.add_dependency 'phony', '~> 2.12' | ||
gem.add_dependency 'activesupport', '>= 3.0' | ||
gem.add_development_dependency 'activerecord', '>= 3.0' | ||
gem.add_development_dependency 'mongoid', '>= 3.0' | ||
end |
Oops, something went wrong.