diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..c29d6ab --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.{sh,markdown}] +indent_size = 4 \ No newline at end of file diff --git a/.ruby-version b/.ruby-version index 276cbf9..437459c 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.3.0 +2.5.0 diff --git a/Appraisals b/Appraisals index e02d8cd..28b94ca 100644 --- a/Appraisals +++ b/Appraisals @@ -2,12 +2,10 @@ appraise '40' do gem 'rails', '~> 4.0.0' end - appraise '41' do gem 'rails', '~> 4.1.0' end - appraise '42' do gem 'rails', '~> 4.2.0' end @@ -25,5 +23,5 @@ appraise '5.2' do end appraise '6.0' do - gem 'rails', '6.0.0.beta3' + gem 'rails', '~> 6.0.0' end diff --git a/README.md b/README.md index f455133..b6b33ba 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ passing an options hash. The following keys are supported: `:length` number of characters, defaults to __32__ -`:type` type of string, can be one of: `:human`, `:auto`, defaults to __:auto__ +`:type` type of string, can be one of: `:human`, `:numbers`, or `:auto` and defaults to __:auto__ Human type generates strings easier to read by excluding ambiguous characters like `1, 5, 8, B, o, O, I, l, s, u`. @@ -63,6 +63,8 @@ Human type generates strings easier to read by excluding ambiguous characters li `:scope` scopes, defines the `ActiveRecord` `scope` applied before calculating the `position` field value. Defaults to __[]__ +`:chars` Custom character list. If provided then `:type` will be ignored. `:chars` can be a range, an array of characters, or a string of characters. + To generate a unique-random on the fly `Uniqueness.generate` that will produce a random field for you. You can also pass some options `Uniqueness.generate(type: :human)`. diff --git a/gemfiles/.bundle/config b/gemfiles/.bundle/config new file mode 100644 index 0000000..c127f80 --- /dev/null +++ b/gemfiles/.bundle/config @@ -0,0 +1,2 @@ +--- +BUNDLE_RETRY: "1" diff --git a/gemfiles/40.gemfile b/gemfiles/40.gemfile new file mode 100644 index 0000000..f844fec --- /dev/null +++ b/gemfiles/40.gemfile @@ -0,0 +1,7 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "rails", "~> 4.0.0" + +gemspec path: "../" diff --git a/gemfiles/40.gemfile.lock b/gemfiles/40.gemfile.lock new file mode 100644 index 0000000..35ab684 --- /dev/null +++ b/gemfiles/40.gemfile.lock @@ -0,0 +1,123 @@ +PATH + remote: .. + specs: + uniqueness (1.1.1) + activerecord (>= 4.0.0) + railties (>= 4.0.0) + +GEM + remote: https://rubygems.org/ + specs: + actionmailer (4.0.13) + actionpack (= 4.0.13) + mail (~> 2.5, >= 2.5.4) + actionpack (4.0.13) + activesupport (= 4.0.13) + builder (~> 3.1.0) + erubis (~> 2.7.0) + rack (~> 1.5.2) + rack-test (~> 0.6.2) + activemodel (4.0.13) + activesupport (= 4.0.13) + builder (~> 3.1.0) + activerecord (4.0.13) + activemodel (= 4.0.13) + activerecord-deprecated_finders (~> 1.0.2) + activesupport (= 4.0.13) + arel (~> 4.0.0) + activerecord-deprecated_finders (1.0.4) + activesupport (4.0.13) + i18n (~> 0.6, >= 0.6.9) + minitest (~> 4.2) + multi_json (~> 1.3) + thread_safe (~> 0.1) + tzinfo (~> 0.3.37) + appraisal (2.2.0) + bundler + rake + thor (>= 0.14.0) + arel (4.0.2) + builder (3.1.4) + concurrent-ruby (1.1.5) + coveralls (0.8.23) + json (>= 1.8, < 3) + simplecov (~> 0.16.1) + term-ansicolor (~> 1.3) + thor (>= 0.19.4, < 2.0) + tins (~> 1.6) + diff-lcs (1.3) + docile (1.3.2) + erubis (2.7.0) + i18n (0.9.5) + concurrent-ruby (~> 1.0) + json (2.2.0) + mail (2.7.1) + mini_mime (>= 0.1.1) + mini_mime (1.0.2) + minitest (4.7.5) + multi_json (1.13.1) + rack (1.5.5) + rack-test (0.6.3) + rack (>= 1.0) + rails (4.0.13) + actionmailer (= 4.0.13) + actionpack (= 4.0.13) + activerecord (= 4.0.13) + activesupport (= 4.0.13) + bundler (>= 1.3.0, < 2.0) + railties (= 4.0.13) + sprockets-rails (~> 2.0) + railties (4.0.13) + actionpack (= 4.0.13) + activesupport (= 4.0.13) + rake (>= 0.8.7) + thor (>= 0.18.1, < 2.0) + rake (12.3.3) + rspec (3.9.0) + rspec-core (~> 3.9.0) + rspec-expectations (~> 3.9.0) + rspec-mocks (~> 3.9.0) + rspec-core (3.9.0) + rspec-support (~> 3.9.0) + rspec-expectations (3.9.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.9.0) + rspec-mocks (3.9.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.9.0) + rspec-support (3.9.0) + simplecov (0.16.1) + docile (~> 1.1) + json (>= 1.8, < 3) + simplecov-html (~> 0.10.0) + simplecov-html (0.10.2) + sprockets (3.7.2) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-rails (2.3.3) + actionpack (>= 3.0) + activesupport (>= 3.0) + sprockets (>= 2.8, < 4.0) + sqlite3 (1.3.13) + term-ansicolor (1.7.1) + tins (~> 1.0) + thor (0.20.3) + thread_safe (0.3.6) + tins (1.21.1) + tzinfo (0.3.55) + +PLATFORMS + ruby + +DEPENDENCIES + appraisal + bundler (~> 1.17) + coveralls + rails (~> 4.0.0) + rake (~> 12.0) + rspec + sqlite3 (~> 1.3, < 1.4) + uniqueness! + +BUNDLED WITH + 1.17.3 diff --git a/gemfiles/41.gemfile b/gemfiles/41.gemfile new file mode 100644 index 0000000..f4a887f --- /dev/null +++ b/gemfiles/41.gemfile @@ -0,0 +1,7 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "rails", "~> 4.1.0" + +gemspec path: "../" diff --git a/gemfiles/41.gemfile.lock b/gemfiles/41.gemfile.lock new file mode 100644 index 0000000..fea5a70 --- /dev/null +++ b/gemfiles/41.gemfile.lock @@ -0,0 +1,127 @@ +PATH + remote: .. + specs: + uniqueness (1.1.1) + activerecord (>= 4.0.0) + railties (>= 4.0.0) + +GEM + remote: https://rubygems.org/ + specs: + actionmailer (4.1.16) + actionpack (= 4.1.16) + actionview (= 4.1.16) + mail (~> 2.5, >= 2.5.4) + actionpack (4.1.16) + actionview (= 4.1.16) + activesupport (= 4.1.16) + rack (~> 1.5.2) + rack-test (~> 0.6.2) + actionview (4.1.16) + activesupport (= 4.1.16) + builder (~> 3.1) + erubis (~> 2.7.0) + activemodel (4.1.16) + activesupport (= 4.1.16) + builder (~> 3.1) + activerecord (4.1.16) + activemodel (= 4.1.16) + activesupport (= 4.1.16) + arel (~> 5.0.0) + activesupport (4.1.16) + i18n (~> 0.6, >= 0.6.9) + json (~> 1.7, >= 1.7.7) + minitest (~> 5.1) + thread_safe (~> 0.1) + tzinfo (~> 1.1) + appraisal (2.2.0) + bundler + rake + thor (>= 0.14.0) + arel (5.0.1.20140414130214) + builder (3.2.3) + concurrent-ruby (1.1.5) + coveralls (0.8.23) + json (>= 1.8, < 3) + simplecov (~> 0.16.1) + term-ansicolor (~> 1.3) + thor (>= 0.19.4, < 2.0) + tins (~> 1.6) + diff-lcs (1.3) + docile (1.3.2) + erubis (2.7.0) + i18n (0.9.5) + concurrent-ruby (~> 1.0) + json (1.8.6) + mail (2.7.1) + mini_mime (>= 0.1.1) + mini_mime (1.0.2) + minitest (5.12.2) + rack (1.5.5) + rack-test (0.6.3) + rack (>= 1.0) + rails (4.1.16) + actionmailer (= 4.1.16) + actionpack (= 4.1.16) + actionview (= 4.1.16) + activemodel (= 4.1.16) + activerecord (= 4.1.16) + activesupport (= 4.1.16) + bundler (>= 1.3.0, < 2.0) + railties (= 4.1.16) + sprockets-rails (~> 2.0) + railties (4.1.16) + actionpack (= 4.1.16) + activesupport (= 4.1.16) + rake (>= 0.8.7) + thor (>= 0.18.1, < 2.0) + rake (12.3.3) + rspec (3.9.0) + rspec-core (~> 3.9.0) + rspec-expectations (~> 3.9.0) + rspec-mocks (~> 3.9.0) + rspec-core (3.9.0) + rspec-support (~> 3.9.0) + rspec-expectations (3.9.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.9.0) + rspec-mocks (3.9.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.9.0) + rspec-support (3.9.0) + simplecov (0.16.1) + docile (~> 1.1) + json (>= 1.8, < 3) + simplecov-html (~> 0.10.0) + simplecov-html (0.10.2) + sprockets (3.7.2) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-rails (2.3.3) + actionpack (>= 3.0) + activesupport (>= 3.0) + sprockets (>= 2.8, < 4.0) + sqlite3 (1.3.13) + term-ansicolor (1.7.1) + tins (~> 1.0) + thor (0.20.3) + thread_safe (0.3.6) + tins (1.21.1) + tzinfo (1.2.5) + thread_safe (~> 0.1) + +PLATFORMS + ruby + +DEPENDENCIES + appraisal + bundler (~> 1.17) + coveralls + rails (~> 4.1.0) + rake (~> 12.0) + rspec + sqlite3 (~> 1.3, < 1.4) + uniqueness! + +BUNDLED WITH + 1.17.3 diff --git a/gemfiles/42.gemfile b/gemfiles/42.gemfile new file mode 100644 index 0000000..6977eb0 --- /dev/null +++ b/gemfiles/42.gemfile @@ -0,0 +1,7 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "rails", "~> 4.2.0" + +gemspec path: "../" diff --git a/gemfiles/42.gemfile.lock b/gemfiles/42.gemfile.lock new file mode 100644 index 0000000..d44fa01 --- /dev/null +++ b/gemfiles/42.gemfile.lock @@ -0,0 +1,153 @@ +PATH + remote: .. + specs: + uniqueness (1.1.1) + activerecord (>= 4.0.0) + railties (>= 4.0.0) + +GEM + remote: https://rubygems.org/ + specs: + actionmailer (4.2.11.1) + actionpack (= 4.2.11.1) + actionview (= 4.2.11.1) + activejob (= 4.2.11.1) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 1.0, >= 1.0.5) + actionpack (4.2.11.1) + actionview (= 4.2.11.1) + activesupport (= 4.2.11.1) + rack (~> 1.6) + rack-test (~> 0.6.2) + rails-dom-testing (~> 1.0, >= 1.0.5) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + actionview (4.2.11.1) + activesupport (= 4.2.11.1) + builder (~> 3.1) + erubis (~> 2.7.0) + rails-dom-testing (~> 1.0, >= 1.0.5) + rails-html-sanitizer (~> 1.0, >= 1.0.3) + activejob (4.2.11.1) + activesupport (= 4.2.11.1) + globalid (>= 0.3.0) + activemodel (4.2.11.1) + activesupport (= 4.2.11.1) + builder (~> 3.1) + activerecord (4.2.11.1) + activemodel (= 4.2.11.1) + activesupport (= 4.2.11.1) + arel (~> 6.0) + activesupport (4.2.11.1) + i18n (~> 0.7) + minitest (~> 5.1) + thread_safe (~> 0.3, >= 0.3.4) + tzinfo (~> 1.1) + appraisal (2.2.0) + bundler + rake + thor (>= 0.14.0) + arel (6.0.4) + builder (3.2.3) + concurrent-ruby (1.1.5) + coveralls (0.8.23) + json (>= 1.8, < 3) + simplecov (~> 0.16.1) + term-ansicolor (~> 1.3) + thor (>= 0.19.4, < 2.0) + tins (~> 1.6) + crass (1.0.5) + diff-lcs (1.3) + docile (1.3.2) + erubis (2.7.0) + globalid (0.4.2) + activesupport (>= 4.2.0) + i18n (0.9.5) + concurrent-ruby (~> 1.0) + json (2.2.0) + loofah (2.3.1) + crass (~> 1.0.2) + nokogiri (>= 1.5.9) + mail (2.7.1) + mini_mime (>= 0.1.1) + mini_mime (1.0.2) + mini_portile2 (2.4.0) + minitest (5.12.2) + nokogiri (1.10.4) + mini_portile2 (~> 2.4.0) + rack (1.6.11) + rack-test (0.6.3) + rack (>= 1.0) + rails (4.2.11.1) + actionmailer (= 4.2.11.1) + actionpack (= 4.2.11.1) + actionview (= 4.2.11.1) + activejob (= 4.2.11.1) + activemodel (= 4.2.11.1) + activerecord (= 4.2.11.1) + activesupport (= 4.2.11.1) + bundler (>= 1.3.0, < 2.0) + railties (= 4.2.11.1) + sprockets-rails + rails-deprecated_sanitizer (1.0.3) + activesupport (>= 4.2.0.alpha) + rails-dom-testing (1.0.9) + activesupport (>= 4.2.0, < 5.0) + nokogiri (~> 1.6) + rails-deprecated_sanitizer (>= 1.0.1) + rails-html-sanitizer (1.3.0) + loofah (~> 2.3) + railties (4.2.11.1) + actionpack (= 4.2.11.1) + activesupport (= 4.2.11.1) + rake (>= 0.8.7) + thor (>= 0.18.1, < 2.0) + rake (12.3.3) + rspec (3.9.0) + rspec-core (~> 3.9.0) + rspec-expectations (~> 3.9.0) + rspec-mocks (~> 3.9.0) + rspec-core (3.9.0) + rspec-support (~> 3.9.0) + rspec-expectations (3.9.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.9.0) + rspec-mocks (3.9.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.9.0) + rspec-support (3.9.0) + simplecov (0.16.1) + docile (~> 1.1) + json (>= 1.8, < 3) + simplecov-html (~> 0.10.0) + simplecov-html (0.10.2) + sprockets (4.0.0) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-rails (3.2.1) + actionpack (>= 4.0) + activesupport (>= 4.0) + sprockets (>= 3.0.0) + sqlite3 (1.3.13) + term-ansicolor (1.7.1) + tins (~> 1.0) + thor (0.20.3) + thread_safe (0.3.6) + tins (1.21.1) + tzinfo (1.2.5) + thread_safe (~> 0.1) + +PLATFORMS + ruby + +DEPENDENCIES + appraisal + bundler (~> 1.17) + coveralls + rails (~> 4.2.0) + rake (~> 12.0) + rspec + sqlite3 (~> 1.3, < 1.4) + uniqueness! + +BUNDLED WITH + 1.17.3 diff --git a/gemfiles/5.0.gemfile b/gemfiles/5.0.gemfile index 6b40de0..10f52e7 100644 --- a/gemfiles/5.0.gemfile +++ b/gemfiles/5.0.gemfile @@ -2,7 +2,6 @@ source "https://rubygems.org" -gem "bundler", "~> 2.0" gem "rails", "~> 5.0.0" gemspec path: "../" diff --git a/gemfiles/5.0.gemfile.lock b/gemfiles/5.0.gemfile.lock index dc49fbf..430ec9a 100644 --- a/gemfiles/5.0.gemfile.lock +++ b/gemfiles/5.0.gemfile.lock @@ -1,7 +1,7 @@ PATH remote: .. specs: - uniqueness (1.1.0) + uniqueness (1.1.1) activerecord (>= 4.0.0) railties (>= 4.0.0) @@ -52,32 +52,32 @@ GEM arel (7.1.4) builder (3.2.3) concurrent-ruby (1.1.5) - coveralls (0.8.22) + coveralls (0.8.23) json (>= 1.8, < 3) simplecov (~> 0.16.1) term-ansicolor (~> 1.3) - thor (~> 0.19.4) + thor (>= 0.19.4, < 2.0) tins (~> 1.6) - crass (1.0.4) + crass (1.0.5) diff-lcs (1.3) - docile (1.3.1) + docile (1.3.2) erubis (2.7.0) globalid (0.4.2) activesupport (>= 4.2.0) - i18n (1.6.0) + i18n (1.7.0) concurrent-ruby (~> 1.0) json (2.2.0) - loofah (2.2.3) + loofah (2.3.1) crass (~> 1.0.2) nokogiri (>= 1.5.9) mail (2.7.1) mini_mime (>= 0.1.1) method_source (0.9.2) - mini_mime (1.0.1) + mini_mime (1.0.2) mini_portile2 (2.4.0) - minitest (5.11.3) - nio4r (2.3.1) - nokogiri (1.10.2) + minitest (5.12.2) + nio4r (2.5.2) + nokogiri (1.10.4) mini_portile2 (~> 2.4.0) rack (2.0.7) rack-test (0.6.3) @@ -97,34 +97,34 @@ GEM rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) - rails-html-sanitizer (1.0.4) - loofah (~> 2.2, >= 2.2.2) + rails-html-sanitizer (1.3.0) + loofah (~> 2.3) railties (5.0.7.2) actionpack (= 5.0.7.2) activesupport (= 5.0.7.2) method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - rake (12.3.2) - rspec (3.8.0) - rspec-core (~> 3.8.0) - rspec-expectations (~> 3.8.0) - rspec-mocks (~> 3.8.0) - rspec-core (3.8.0) - rspec-support (~> 3.8.0) - rspec-expectations (3.8.2) + rake (12.3.3) + rspec (3.9.0) + rspec-core (~> 3.9.0) + rspec-expectations (~> 3.9.0) + rspec-mocks (~> 3.9.0) + rspec-core (3.9.0) + rspec-support (~> 3.9.0) + rspec-expectations (3.9.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-mocks (3.8.0) + rspec-support (~> 3.9.0) + rspec-mocks (3.9.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-support (3.8.0) + rspec-support (~> 3.9.0) + rspec-support (3.9.0) simplecov (0.16.1) docile (~> 1.1) json (>= 1.8, < 3) simplecov-html (~> 0.10.0) simplecov-html (0.10.2) - sprockets (3.7.2) + sprockets (4.0.0) concurrent-ruby (~> 1.0) rack (> 1, < 3) sprockets-rails (3.2.1) @@ -134,21 +134,21 @@ GEM sqlite3 (1.3.13) term-ansicolor (1.7.1) tins (~> 1.0) - thor (0.19.4) + thor (0.20.3) thread_safe (0.3.6) - tins (1.20.2) + tins (1.21.1) tzinfo (1.2.5) thread_safe (~> 0.1) websocket-driver (0.6.5) websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.3) + websocket-extensions (0.1.4) PLATFORMS ruby DEPENDENCIES appraisal - bundler (~> 2.0) + bundler (~> 1.17) coveralls rails (~> 5.0.0) rake (~> 12.0) @@ -157,4 +157,4 @@ DEPENDENCIES uniqueness! BUNDLED WITH - 2.0.1 + 1.17.3 diff --git a/gemfiles/5.1.gemfile b/gemfiles/5.1.gemfile index 599e01b..6100e83 100644 --- a/gemfiles/5.1.gemfile +++ b/gemfiles/5.1.gemfile @@ -2,7 +2,6 @@ source "https://rubygems.org" -gem "bundler", "~> 2.0" gem "rails", "~> 5.1.0" gemspec path: "../" diff --git a/gemfiles/5.1.gemfile.lock b/gemfiles/5.1.gemfile.lock index 4beaee1..6bf6cd7 100644 --- a/gemfiles/5.1.gemfile.lock +++ b/gemfiles/5.1.gemfile.lock @@ -1,7 +1,7 @@ PATH remote: .. specs: - uniqueness (1.1.0) + uniqueness (1.1.1) activerecord (>= 4.0.0) railties (>= 4.0.0) @@ -52,32 +52,32 @@ GEM arel (8.0.0) builder (3.2.3) concurrent-ruby (1.1.5) - coveralls (0.8.22) + coveralls (0.8.23) json (>= 1.8, < 3) simplecov (~> 0.16.1) term-ansicolor (~> 1.3) - thor (~> 0.19.4) + thor (>= 0.19.4, < 2.0) tins (~> 1.6) - crass (1.0.4) + crass (1.0.5) diff-lcs (1.3) - docile (1.3.1) - erubi (1.8.0) + docile (1.3.2) + erubi (1.9.0) globalid (0.4.2) activesupport (>= 4.2.0) - i18n (1.6.0) + i18n (1.7.0) concurrent-ruby (~> 1.0) json (2.2.0) - loofah (2.2.3) + loofah (2.3.1) crass (~> 1.0.2) nokogiri (>= 1.5.9) mail (2.7.1) mini_mime (>= 0.1.1) method_source (0.9.2) - mini_mime (1.0.1) + mini_mime (1.0.2) mini_portile2 (2.4.0) - minitest (5.11.3) - nio4r (2.3.1) - nokogiri (1.10.2) + minitest (5.12.2) + nio4r (2.5.2) + nokogiri (1.10.4) mini_portile2 (~> 2.4.0) rack (2.0.7) rack-test (1.1.0) @@ -97,34 +97,34 @@ GEM rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) - rails-html-sanitizer (1.0.4) - loofah (~> 2.2, >= 2.2.2) + rails-html-sanitizer (1.3.0) + loofah (~> 2.3) railties (5.1.7) actionpack (= 5.1.7) activesupport (= 5.1.7) method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - rake (12.3.2) - rspec (3.8.0) - rspec-core (~> 3.8.0) - rspec-expectations (~> 3.8.0) - rspec-mocks (~> 3.8.0) - rspec-core (3.8.0) - rspec-support (~> 3.8.0) - rspec-expectations (3.8.2) + rake (12.3.3) + rspec (3.9.0) + rspec-core (~> 3.9.0) + rspec-expectations (~> 3.9.0) + rspec-mocks (~> 3.9.0) + rspec-core (3.9.0) + rspec-support (~> 3.9.0) + rspec-expectations (3.9.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-mocks (3.8.0) + rspec-support (~> 3.9.0) + rspec-mocks (3.9.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-support (3.8.0) + rspec-support (~> 3.9.0) + rspec-support (3.9.0) simplecov (0.16.1) docile (~> 1.1) json (>= 1.8, < 3) simplecov-html (~> 0.10.0) simplecov-html (0.10.2) - sprockets (3.7.2) + sprockets (4.0.0) concurrent-ruby (~> 1.0) rack (> 1, < 3) sprockets-rails (3.2.1) @@ -134,21 +134,21 @@ GEM sqlite3 (1.3.13) term-ansicolor (1.7.1) tins (~> 1.0) - thor (0.19.4) + thor (0.20.3) thread_safe (0.3.6) - tins (1.20.2) + tins (1.21.1) tzinfo (1.2.5) thread_safe (~> 0.1) websocket-driver (0.6.5) websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.3) + websocket-extensions (0.1.4) PLATFORMS ruby DEPENDENCIES appraisal - bundler (~> 2.0) + bundler (~> 1.17) coveralls rails (~> 5.1.0) rake (~> 12.0) @@ -157,4 +157,4 @@ DEPENDENCIES uniqueness! BUNDLED WITH - 2.0.1 + 1.17.3 diff --git a/gemfiles/5.2.gemfile b/gemfiles/5.2.gemfile index 31f3118..5a706dc 100644 --- a/gemfiles/5.2.gemfile +++ b/gemfiles/5.2.gemfile @@ -2,7 +2,6 @@ source "https://rubygems.org" -gem "bundler", "~> 2.0" gem "rails", "~> 5.2.0" gemspec path: "../" diff --git a/gemfiles/5.2.gemfile.lock b/gemfiles/5.2.gemfile.lock index ffcfe31..8545e04 100644 --- a/gemfiles/5.2.gemfile.lock +++ b/gemfiles/5.2.gemfile.lock @@ -1,7 +1,7 @@ PATH remote: .. specs: - uniqueness (1.1.0) + uniqueness (1.1.1) activerecord (>= 4.0.0) railties (>= 4.0.0) @@ -56,22 +56,22 @@ GEM arel (9.0.0) builder (3.2.3) concurrent-ruby (1.1.5) - coveralls (0.8.22) + coveralls (0.8.23) json (>= 1.8, < 3) simplecov (~> 0.16.1) term-ansicolor (~> 1.3) - thor (~> 0.19.4) + thor (>= 0.19.4, < 2.0) tins (~> 1.6) - crass (1.0.4) + crass (1.0.5) diff-lcs (1.3) - docile (1.3.1) - erubi (1.8.0) + docile (1.3.2) + erubi (1.9.0) globalid (0.4.2) activesupport (>= 4.2.0) - i18n (1.6.0) + i18n (1.7.0) concurrent-ruby (~> 1.0) json (2.2.0) - loofah (2.2.3) + loofah (2.3.1) crass (~> 1.0.2) nokogiri (>= 1.5.9) mail (2.7.1) @@ -80,11 +80,11 @@ GEM mimemagic (~> 0.3.2) method_source (0.9.2) mimemagic (0.3.3) - mini_mime (1.0.1) + mini_mime (1.0.2) mini_portile2 (2.4.0) - minitest (5.11.3) - nio4r (2.3.1) - nokogiri (1.10.2) + minitest (5.12.2) + nio4r (2.5.2) + nokogiri (1.10.4) mini_portile2 (~> 2.4.0) rack (2.0.7) rack-test (1.1.0) @@ -105,34 +105,34 @@ GEM rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) - rails-html-sanitizer (1.0.4) - loofah (~> 2.2, >= 2.2.2) + rails-html-sanitizer (1.3.0) + loofah (~> 2.3) railties (5.2.3) actionpack (= 5.2.3) activesupport (= 5.2.3) method_source rake (>= 0.8.7) thor (>= 0.19.0, < 2.0) - rake (12.3.2) - rspec (3.8.0) - rspec-core (~> 3.8.0) - rspec-expectations (~> 3.8.0) - rspec-mocks (~> 3.8.0) - rspec-core (3.8.0) - rspec-support (~> 3.8.0) - rspec-expectations (3.8.2) + rake (12.3.3) + rspec (3.9.0) + rspec-core (~> 3.9.0) + rspec-expectations (~> 3.9.0) + rspec-mocks (~> 3.9.0) + rspec-core (3.9.0) + rspec-support (~> 3.9.0) + rspec-expectations (3.9.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-mocks (3.8.0) + rspec-support (~> 3.9.0) + rspec-mocks (3.9.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-support (3.8.0) + rspec-support (~> 3.9.0) + rspec-support (3.9.0) simplecov (0.16.1) docile (~> 1.1) json (>= 1.8, < 3) simplecov-html (~> 0.10.0) simplecov-html (0.10.2) - sprockets (3.7.2) + sprockets (4.0.0) concurrent-ruby (~> 1.0) rack (> 1, < 3) sprockets-rails (3.2.1) @@ -142,21 +142,21 @@ GEM sqlite3 (1.3.13) term-ansicolor (1.7.1) tins (~> 1.0) - thor (0.19.4) + thor (0.20.3) thread_safe (0.3.6) - tins (1.20.2) + tins (1.21.1) tzinfo (1.2.5) thread_safe (~> 0.1) - websocket-driver (0.7.0) + websocket-driver (0.7.1) websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.3) + websocket-extensions (0.1.4) PLATFORMS ruby DEPENDENCIES appraisal - bundler (~> 2.0) + bundler (~> 1.17) coveralls rails (~> 5.2.0) rake (~> 12.0) @@ -165,4 +165,4 @@ DEPENDENCIES uniqueness! BUNDLED WITH - 2.0.1 + 1.17.3 diff --git a/gemfiles/6.0.gemfile b/gemfiles/6.0.gemfile index bbbbe97..15b9b27 100644 --- a/gemfiles/6.0.gemfile +++ b/gemfiles/6.0.gemfile @@ -2,7 +2,6 @@ source "https://rubygems.org" -gem "bundler", "~> 2.0" -gem "rails", "6.0.0.beta3" +gem "rails", "~> 6.0.0" gemspec path: "../" diff --git a/gemfiles/6.0.gemfile.lock b/gemfiles/6.0.gemfile.lock index 83472bf..5cdd232 100644 --- a/gemfiles/6.0.gemfile.lock +++ b/gemfiles/6.0.gemfile.lock @@ -1,93 +1,90 @@ PATH remote: .. specs: - uniqueness (1.1.0) + uniqueness (1.1.1) activerecord (>= 4.0.0) railties (>= 4.0.0) GEM remote: https://rubygems.org/ specs: - actioncable (6.0.0.beta3) - actionpack (= 6.0.0.beta3) + actioncable (6.0.0) + actionpack (= 6.0.0) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (6.0.0.beta3) - actionpack (= 6.0.0.beta3) - activejob (= 6.0.0.beta3) - activerecord (= 6.0.0.beta3) - activestorage (= 6.0.0.beta3) - activesupport (= 6.0.0.beta3) + actionmailbox (6.0.0) + actionpack (= 6.0.0) + activejob (= 6.0.0) + activerecord (= 6.0.0) + activestorage (= 6.0.0) + activesupport (= 6.0.0) mail (>= 2.7.1) - actionmailer (6.0.0.beta3) - actionpack (= 6.0.0.beta3) - actionview (= 6.0.0.beta3) - activejob (= 6.0.0.beta3) + actionmailer (6.0.0) + actionpack (= 6.0.0) + actionview (= 6.0.0) + activejob (= 6.0.0) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (6.0.0.beta3) - actionview (= 6.0.0.beta3) - activesupport (= 6.0.0.beta3) + actionpack (6.0.0) + actionview (= 6.0.0) + activesupport (= 6.0.0) rack (~> 2.0) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - actiontext (6.0.0.beta3) - actionpack (= 6.0.0.beta3) - activerecord (= 6.0.0.beta3) - activestorage (= 6.0.0.beta3) - activesupport (= 6.0.0.beta3) + rails-html-sanitizer (~> 1.0, >= 1.2.0) + actiontext (6.0.0) + actionpack (= 6.0.0) + activerecord (= 6.0.0) + activestorage (= 6.0.0) + activesupport (= 6.0.0) nokogiri (>= 1.8.5) - actionview (6.0.0.beta3) - activesupport (= 6.0.0.beta3) + actionview (6.0.0) + activesupport (= 6.0.0) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (6.0.0.beta3) - activesupport (= 6.0.0.beta3) + rails-html-sanitizer (~> 1.1, >= 1.2.0) + activejob (6.0.0) + activesupport (= 6.0.0) globalid (>= 0.3.6) - activemodel (6.0.0.beta3) - activesupport (= 6.0.0.beta3) - activerecord (6.0.0.beta3) - activemodel (= 6.0.0.beta3) - activesupport (= 6.0.0.beta3) - activestorage (6.0.0.beta3) - actionpack (= 6.0.0.beta3) - activerecord (= 6.0.0.beta3) + activemodel (6.0.0) + activesupport (= 6.0.0) + activerecord (6.0.0) + activemodel (= 6.0.0) + activesupport (= 6.0.0) + activestorage (6.0.0) + actionpack (= 6.0.0) + activejob (= 6.0.0) + activerecord (= 6.0.0) marcel (~> 0.3.1) - activesupport (6.0.0.beta3) + activesupport (6.0.0) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) - zeitwerk (~> 1.3, >= 1.3.1) + zeitwerk (~> 2.1, >= 2.1.8) appraisal (2.2.0) bundler rake thor (>= 0.14.0) builder (3.2.3) concurrent-ruby (1.1.5) - coveralls (0.7.1) - multi_json (~> 1.3) - rest-client - simplecov (>= 0.7) - term-ansicolor - thor - crass (1.0.4) + coveralls (0.8.23) + json (>= 1.8, < 3) + simplecov (~> 0.16.1) + term-ansicolor (~> 1.3) + thor (>= 0.19.4, < 2.0) + tins (~> 1.6) + crass (1.0.5) diff-lcs (1.3) - docile (1.3.1) - domain_name (0.5.20180417) - unf (>= 0.0.5, < 1.0.0) - erubi (1.8.0) + docile (1.3.2) + erubi (1.9.0) globalid (0.4.2) activesupport (>= 4.2.0) - http-cookie (1.0.3) - domain_name (~> 0.5) - i18n (1.6.0) + i18n (1.7.0) concurrent-ruby (~> 1.0) json (2.2.0) - loofah (2.2.3) + loofah (2.3.1) crass (~> 1.0.2) nokogiri (>= 1.5.9) mail (2.7.1) @@ -95,71 +92,62 @@ GEM marcel (0.3.3) mimemagic (~> 0.3.2) method_source (0.9.2) - mime-types (3.2.2) - mime-types-data (~> 3.2015) - mime-types-data (3.2019.0331) mimemagic (0.3.3) - mini_mime (1.0.1) + mini_mime (1.0.2) mini_portile2 (2.4.0) - minitest (5.11.3) - multi_json (1.13.1) - netrc (0.11.0) - nio4r (2.3.1) - nokogiri (1.10.2) + minitest (5.12.2) + nio4r (2.5.2) + nokogiri (1.10.4) mini_portile2 (~> 2.4.0) rack (2.0.7) rack-test (1.1.0) rack (>= 1.0, < 3) - rails (6.0.0.beta3) - actioncable (= 6.0.0.beta3) - actionmailbox (= 6.0.0.beta3) - actionmailer (= 6.0.0.beta3) - actionpack (= 6.0.0.beta3) - actiontext (= 6.0.0.beta3) - actionview (= 6.0.0.beta3) - activejob (= 6.0.0.beta3) - activemodel (= 6.0.0.beta3) - activerecord (= 6.0.0.beta3) - activestorage (= 6.0.0.beta3) - activesupport (= 6.0.0.beta3) + rails (6.0.0) + actioncable (= 6.0.0) + actionmailbox (= 6.0.0) + actionmailer (= 6.0.0) + actionpack (= 6.0.0) + actiontext (= 6.0.0) + actionview (= 6.0.0) + activejob (= 6.0.0) + activemodel (= 6.0.0) + activerecord (= 6.0.0) + activestorage (= 6.0.0) + activesupport (= 6.0.0) bundler (>= 1.3.0) - railties (= 6.0.0.beta3) + railties (= 6.0.0) sprockets-rails (>= 2.0.0) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) - rails-html-sanitizer (1.0.4) - loofah (~> 2.2, >= 2.2.2) - railties (6.0.0.beta3) - actionpack (= 6.0.0.beta3) - activesupport (= 6.0.0.beta3) + rails-html-sanitizer (1.3.0) + loofah (~> 2.3) + railties (6.0.0) + actionpack (= 6.0.0) + activesupport (= 6.0.0) method_source rake (>= 0.8.7) thor (>= 0.20.3, < 2.0) - rake (12.3.2) - rest-client (2.0.2) - http-cookie (>= 1.0.2, < 2.0) - mime-types (>= 1.16, < 4.0) - netrc (~> 0.8) - rspec (3.8.0) - rspec-core (~> 3.8.0) - rspec-expectations (~> 3.8.0) - rspec-mocks (~> 3.8.0) - rspec-core (3.8.0) - rspec-support (~> 3.8.0) - rspec-expectations (3.8.2) + rake (12.3.3) + rspec (3.9.0) + rspec-core (~> 3.9.0) + rspec-expectations (~> 3.9.0) + rspec-mocks (~> 3.9.0) + rspec-core (3.9.0) + rspec-support (~> 3.9.0) + rspec-expectations (3.9.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-mocks (3.8.0) + rspec-support (~> 3.9.0) + rspec-mocks (3.9.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-support (3.8.0) + rspec-support (~> 3.9.0) + rspec-support (3.9.0) simplecov (0.16.1) docile (~> 1.1) json (>= 1.8, < 3) simplecov-html (~> 0.10.0) simplecov-html (0.10.2) - sprockets (3.7.2) + sprockets (4.0.0) concurrent-ruby (~> 1.0) rack (> 1, < 3) sprockets-rails (3.2.1) @@ -171,29 +159,26 @@ GEM tins (~> 1.0) thor (0.20.3) thread_safe (0.3.6) - tins (1.20.2) + tins (1.21.1) tzinfo (1.2.5) thread_safe (~> 0.1) - unf (0.1.4) - unf_ext - unf_ext (0.0.7.5) - websocket-driver (0.7.0) + websocket-driver (0.7.1) websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.3) - zeitwerk (1.4.3) + websocket-extensions (0.1.4) + zeitwerk (2.2.0) PLATFORMS ruby DEPENDENCIES appraisal - bundler (~> 2.0) + bundler (~> 1.17) coveralls - rails (= 6.0.0.beta3) + rails (~> 6.0.0) rake (~> 12.0) rspec sqlite3 (~> 1.3, < 1.4) uniqueness! BUNDLED WITH - 2.0.1 + 1.17.3 diff --git a/lib/uniqueness/generator.rb b/lib/uniqueness/generator.rb index e70421e..6091c35 100644 --- a/lib/uniqueness/generator.rb +++ b/lib/uniqueness/generator.rb @@ -3,12 +3,12 @@ module Uniqueness class << self def generate(opts = {}) - options ||= {} options = uniqueness_default_options.merge(opts) dict = uniqueness_dictionary - options[:blacklist] dict -= [*(:A..:Z)].map(&:to_s) unless options[:case_sensitive] dict -= uniqueness_ambigious_dictionary if options[:type].to_sym == :human dict = uniqueness_numbers_dictionary if options[:type].to_sym == :numbers + dict = uniqueness_custom_dictionary(options[:chars]) if options[:chars].present? code = Array.new(options[:length]).map { dict[SecureRandom.random_number(dict.length)] }.join "#{options[:prefix]}#{code}#{options[:suffix]}" end @@ -26,6 +26,12 @@ def uniqueness_numbers_dictionary [*(0..9)].map(&:to_s) end + def uniqueness_custom_dictionary(chars = []) + chars = [*chars] if chars.is_a?(Range) + chars = chars.map(&:to_s) if chars.is_a?(Array) + chars + end + # Default sorting options def uniqueness_default_options { diff --git a/lib/uniqueness/model.rb b/lib/uniqueness/model.rb index e89e507..9d6a7df 100644 --- a/lib/uniqueness/model.rb +++ b/lib/uniqueness/model.rb @@ -46,17 +46,21 @@ def has_unique_field(name, options = {}) end validate :uniqueness_validation - define_method("regenerate_#{name}") { update(name => Uniqueness.generate(self.uniqueness_options[name])) } + + define_method("regenerate_#{name}") do + value = Uniqueness.generate(uniqueness_options[name]) + send("#{name}=", value) + end end end # Generates a new code based on given options def uniqueness_generate - self.uniqueness_options.each do |field, options| + uniqueness_options.each do |field, options| value = send(field) unless value.present? value = Uniqueness.generate(options) - self.send("#{field}=", value) + send("#{field}=", value) end end end diff --git a/lib/uniqueness/version.rb b/lib/uniqueness/version.rb index d8025c9..ff4ef0e 100644 --- a/lib/uniqueness/version.rb +++ b/lib/uniqueness/version.rb @@ -1,3 +1,3 @@ module Uniqueness - VERSION = '1.1.0'.freeze + VERSION = '1.1.1'.freeze end diff --git a/spec/generator/generator_spec.rb b/spec/generator/generator_spec.rb index 6386233..31bc1e2 100644 --- a/spec/generator/generator_spec.rb +++ b/spec/generator/generator_spec.rb @@ -6,5 +6,8 @@ it { expect(Uniqueness.generate(type: :numbers)).to match(/^[0-9]+$/) } it { expect(Uniqueness.generate(prefix: 'hassan').index('hassan')).to eq 0 } it { expect(Uniqueness.generate(suffix: 'hassan')).to end_with "hassan" } + it { expect(Uniqueness.generate(chars: 'A'..'F')).to match(/^[A-F]+$/) } + it { expect(Uniqueness.generate(chars: ('A'..'F').to_a)).to match(/^[A-F]+$/) } + it { expect(Uniqueness.generate(chars: 'ABCDEF')).to match(/^[A-F]+$/) } end end diff --git a/spec/uniqueness/uniqueness_spec.rb b/spec/uniqueness/uniqueness_spec.rb index d9b2411..6ed24e9 100644 --- a/spec/uniqueness/uniqueness_spec.rb +++ b/spec/uniqueness/uniqueness_spec.rb @@ -63,7 +63,7 @@ end end - context 'intialized new object' do + context 'initialized new object' do it { expect(new_page.after_init_token).not_to be_nil } context 'length' do