-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rubocop + fixes #924
Merged
Merged
Rubocop + fixes #924
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,20 @@ | ||
Metrics/LineLength: | ||
Enabled: false | ||
Metrics/MethodLength: | ||
Enabled: false | ||
Metrics/ClassLength: | ||
Enabled: false | ||
Metrics/BlockLength: | ||
Enabled: false | ||
Metrics/AbcSize: | ||
Enabled: false | ||
Metrics/PerceivedComplexity: | ||
Enabled: false | ||
Metrics/CyclomaticComplexity: | ||
Enabled: false | ||
Style/Documentation: | ||
Enabled: false | ||
Style/DateTime: | ||
Enabled: false | ||
Lint/UnifiedInteger: | ||
Enabled: false |
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 |
---|---|---|
|
@@ -7,7 +7,6 @@ rvm: | |
- 2.3.4 | ||
- 2.4.1 | ||
- ruby-head | ||
script: bundle exec rake test | ||
matrix: | ||
allow_failures: | ||
- rvm: ruby-head |
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,11 +1,4 @@ | ||
source "https://rubygems.org" | ||
source 'https://rubygems.org' | ||
|
||
# Specify your gem's dependencies in faker.gemspec | ||
gemspec | ||
|
||
group :development, :test do | ||
gem "test-unit" | ||
gem "rake" | ||
gem "minitest" | ||
gem "timecop" | ||
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
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,20 +1,25 @@ | ||
$:.push File.expand_path("../lib", __FILE__) | ||
require "faker/version" | ||
$LOAD_PATH.push File.expand_path('lib', __dir__) | ||
require 'faker/version' | ||
|
||
Gem::Specification.new do |s| | ||
s.name = "faker" | ||
s.name = 'faker' | ||
s.version = Faker::VERSION | ||
s.platform = Gem::Platform::RUBY | ||
s.authors = ["Benjamin Curtis"] | ||
s.email = ["[email protected]"] | ||
s.homepage = "https://github.com/stympy/faker" | ||
s.summary = %q{Easily generate fake data} | ||
s.description = %q{Faker, a port of Data::Faker from Perl, is used to easily generate fake data: names, addresses, phone numbers, etc.} | ||
s.authors = ['Benjamin Curtis'] | ||
s.email = ['[email protected]'] | ||
s.homepage = 'https://github.com/stympy/faker' | ||
s.summary = 'Easily generate fake data' | ||
s.description = 'Faker, a port of Data::Faker from Perl, is used to easily generate fake data: names, addresses, phone numbers, etc.' | ||
s.license = 'MIT' | ||
|
||
s.add_runtime_dependency('i18n', '>= 0.7') | ||
s.add_development_dependency('minitest') | ||
s.add_development_dependency('rake') | ||
s.add_development_dependency('rubocop') | ||
s.add_development_dependency('test-unit') | ||
s.add_development_dependency('timecop') | ||
s.required_ruby_version = '>= 2.1' | ||
|
||
s.files = Dir['lib/**/*'] + %w(History.md License.txt CHANGELOG.md README.md) | ||
s.require_paths = ["lib"] | ||
s.files = Dir['lib/**/*'] + %w[History.md License.txt CHANGELOG.md README.md] | ||
s.require_paths = ['lib'] | ||
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 |
---|---|---|
|
@@ -6,4 +6,3 @@ def downcase | |
end | ||
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,9 +1,7 @@ | ||
# -*- coding: utf-8 -*- | ||
mydir = File.expand_path(File.dirname(__FILE__)) | ||
mydir = __dir__ | ||
|
||
begin | ||
require 'psych' | ||
rescue LoadError | ||
end | ||
|
||
require 'i18n' | ||
|
@@ -15,7 +13,6 @@ | |
I18n.load_path += Dir[File.join(mydir, 'locales', '**/*.yml')] | ||
I18n.reload! if I18n.backend.initialized? | ||
|
||
|
||
module Faker | ||
class Config | ||
@locale = nil | ||
|
@@ -45,9 +42,9 @@ class Base | |
Letters = ULetters + Array('a'..'z') | ||
|
||
class << self | ||
## make sure numerify results doesn’t start with a zero | ||
## make sure numerify results do not start with a zero | ||
def numerify(number_string) | ||
number_string.sub(/#/) { (rand(9)+1).to_s }.gsub(/#/) { rand(10).to_s } | ||
number_string.sub(/#/) { rand(1..9).to_s }.gsub(/#/) { rand(10).to_s } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
end | ||
|
||
def letterify(letter_string) | ||
|
@@ -77,26 +74,26 @@ def bothify(string) | |
# | ||
# "U3V 3TP" | ||
# | ||
def regexify(re) | ||
re = re.source if re.respond_to?(:source) # Handle either a Regexp or a String that looks like a Regexp | ||
re. | ||
gsub(/^\/?\^?/, '').gsub(/\$?\/?$/, ''). # Ditch the anchors | ||
gsub(/\{(\d+)\}/, '{\1,\1}').gsub(/\?/, '{0,1}'). # All {2} become {2,2} and ? become {0,1} | ||
gsub(/(\[[^\]]+\])\{(\d+),(\d+)\}/) {|match| $1 * sample(Array(Range.new($2.to_i, $3.to_i))) }. # [12]{1,2} becomes [12] or [12][12] | ||
gsub(/(\([^\)]+\))\{(\d+),(\d+)\}/) {|match| $1 * sample(Array(Range.new($2.to_i, $3.to_i))) }. # (12|34){1,2} becomes (12|34) or (12|34)(12|34) | ||
gsub(/(\\?.)\{(\d+),(\d+)\}/) {|match| $1 * sample(Array(Range.new($2.to_i, $3.to_i))) }. # A{1,2} becomes A or AA or \d{3} becomes \d\d\d | ||
gsub(/\((.*?)\)/) {|match| sample(match.gsub(/[\(\)]/, '').split('|')) }. # (this|that) becomes 'this' or 'that' | ||
gsub(/\[([^\]]+)\]/) {|match| match.gsub(/(\w\-\w)/) {|range| sample(Array(Range.new(*range.split('-')))) } }. # All A-Z inside of [] become C (or X, or whatever) | ||
gsub(/\[([^\]]+)\]/) {|match| sample($1.split('')) }. # All [ABC] become B (or A or C) | ||
gsub('\d') {|match| sample(Numbers) }. | ||
gsub('\w') {|match| sample(Letters) } | ||
def regexify(reg) | ||
reg = reg.source if reg.respond_to?(:source) # Handle either a Regexp or a String that looks like a Regexp | ||
reg | ||
.gsub(%r{^\/?\^?}, '').gsub(%r{\$?\/?$}, '') # Ditch the anchors | ||
.gsub(/\{(\d+)\}/, '{\1,\1}').gsub(/\?/, '{0,1}') # All {2} become {2,2} and ? become {0,1} | ||
.gsub(/(\[[^\]]+\])\{(\d+),(\d+)\}/) { |_match| Regexp.last_match(1) * sample(Array(Range.new(Regexp.last_match(2).to_i, Regexp.last_match(3).to_i))) } # [12]{1,2} becomes [12] or [12][12] | ||
.gsub(/(\([^\)]+\))\{(\d+),(\d+)\}/) { |_match| Regexp.last_match(1) * sample(Array(Range.new(Regexp.last_match(2).to_i, Regexp.last_match(3).to_i))) } # (12|34){1,2} becomes (12|34) or (12|34)(12|34) | ||
.gsub(/(\\?.)\{(\d+),(\d+)\}/) { |_match| Regexp.last_match(1) * sample(Array(Range.new(Regexp.last_match(2).to_i, Regexp.last_match(3).to_i))) } # A{1,2} becomes A or AA or \d{3} becomes \d\d\d | ||
.gsub(/\((.*?)\)/) { |match| sample(match.gsub(/[\(\)]/, '').split('|')) } # (this|that) becomes 'this' or 'that' | ||
.gsub(/\[([^\]]+)\]/) { |match| match.gsub(/(\w\-\w)/) { |range| sample(Array(Range.new(*range.split('-')))) } } # All A-Z inside of [] become C (or X, or whatever) | ||
.gsub(/\[([^\]]+)\]/) { |_match| sample(Regexp.last_match(1).split('')) } # All [ABC] become B (or A or C) | ||
.gsub('\d') { |_match| sample(Numbers) } | ||
.gsub('\w') { |_match| sample(Letters) } | ||
end | ||
|
||
# Helper for the common approach of grabbing a translation | ||
# with an array of values and selecting one of them. | ||
def fetch(key) | ||
fetched = sample(translate("faker.#{key}")) | ||
if fetched && fetched.match(/^\//) && fetched.match(/\/$/) # A regex | ||
if fetched && fetched.match(%r{^\/}) && fetched.match(%r{\/$}) # A regex | ||
regexify(fetched) | ||
else | ||
fetched | ||
|
@@ -108,7 +105,7 @@ def fetch(key) | |
def fetch_all(key) | ||
fetched = translate("faker.#{key}") | ||
fetched = fetched.last if fetched.size <= 1 | ||
if !fetched.respond_to?(:sample) && fetched.match(/^\//) && fetched.match(/\/$/) # A regex | ||
if !fetched.respond_to?(:sample) && fetched.match(%r{^\/}) && fetched.match(%r{\/$}) # A regex | ||
regexify(fetched) | ||
else | ||
fetched | ||
|
@@ -120,7 +117,7 @@ def fetch_all(key) | |
# formatted translation: e.g., "#{first_name} #{last_name}". | ||
def parse(key) | ||
fetched = fetch(key) | ||
parts = fetched.scan(/(\(?)#\{([A-Za-z]+\.)?([^\}]+)\}([^#]+)?/).map {|prefix, kls, meth, etc| | ||
parts = fetched.scan(/(\(?)#\{([A-Za-z]+\.)?([^\}]+)\}([^#]+)?/).map do |prefix, kls, meth, etc| | ||
# If the token had a class Prefix (e.g., Name.first_name) | ||
# grab the constant, otherwise use self | ||
cls = kls ? Faker.const_get(kls.chop) : self | ||
|
@@ -134,8 +131,8 @@ def parse(key) | |
text += cls.respond_to?(meth) ? cls.send(meth) : fetch("#{(kls || self).to_s.split('::').last.downcase}.#{meth.downcase}") | ||
|
||
# And tack on spaces, commas, etc. left over in the string | ||
text += etc.to_s | ||
} | ||
text + etc.to_s | ||
end | ||
# If the fetched key couldn't be parsed, then fallback to numerify | ||
parts.any? ? parts.join : numerify(fetched) | ||
end | ||
|
@@ -146,15 +143,15 @@ def translate(*args) | |
opts = args.last.is_a?(Hash) ? args.pop : {} | ||
opts[:locale] ||= Faker::Config.locale | ||
opts[:raise] = true | ||
I18n.translate(*(args.push(opts))) | ||
I18n.translate(*args.push(opts)) | ||
rescue I18n::MissingTranslationData | ||
opts = args.last.is_a?(Hash) ? args.pop : {} | ||
opts[:locale] = :en | ||
|
||
# Super-simple fallback -- fallback to en if the | ||
# translation was missing. If the translation isn't | ||
# in en either, then it will raise again. | ||
I18n.translate(*(args.push(opts))) | ||
I18n.translate(*args.push(opts)) | ||
end | ||
|
||
# Executes block with given locale set. | ||
|
@@ -175,25 +172,29 @@ def flexible(key) | |
# name: | ||
# girls_name: ["Alice", "Cheryl", "Tatiana"] | ||
# Then you can call Faker::Name.girls_name and it will act like #first_name | ||
def method_missing(m, *args, &block) | ||
def method_missing(mth, *args, &block) | ||
super unless @flexible_key | ||
|
||
# Use the alternate form of translate to get a nil rather than a "missing translation" string | ||
if translation = translate(:faker)[@flexible_key][m] | ||
if (translation = translate(:faker)[@flexible_key][mth]) | ||
sample(translation) | ||
else | ||
super | ||
end | ||
end | ||
|
||
def respond_to_missing?(method_name, include_private = false) | ||
super | ||
end | ||
|
||
# Generates a random value between the interval | ||
def rand_in_range(from, to) | ||
from, to = to, from if to < from | ||
rand(from..to) | ||
end | ||
|
||
def unique(max_retries = 10_000) | ||
@unique_generator ||= UniqueGenerator.new(self, max_retries) | ||
@unique ||= UniqueGenerator.new(self, max_retries) | ||
end | ||
|
||
def sample(list) | ||
|
@@ -217,7 +218,7 @@ def rand(max = nil) | |
end | ||
end | ||
|
||
Dir.glob(File.join(File.dirname(__FILE__), 'faker','*.rb')).sort.each {|f| require f } | ||
Dir.glob(File.join(File.dirname(__FILE__), 'faker', '*.rb')).sort.each { |f| require f } | ||
|
||
require 'extensions/array' | ||
require 'extensions/symbol' | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are we removing this line? @stephengroat
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should actually add the rubocop script instead of removing this script.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, i have a gem that removes the defaults from
.travis.yml
automatically.i can add it back in if needed.
rubocop
is now integrated into the defaultrake
task