authlogic 3.4.6 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. checksums.yaml +5 -5
  2. data/.github/ISSUE_TEMPLATE.md +13 -0
  3. data/.github/triage.md +87 -0
  4. data/.gitignore +4 -0
  5. data/.rubocop.yml +127 -0
  6. data/.rubocop_todo.yml +65 -0
  7. data/.travis.yml +18 -10
  8. data/CHANGELOG.md +156 -6
  9. data/CONTRIBUTING.md +71 -3
  10. data/Gemfile +2 -2
  11. data/README.md +386 -0
  12. data/Rakefile +13 -7
  13. data/UPGRADING.md +22 -0
  14. data/authlogic.gemspec +33 -22
  15. data/lib/authlogic.rb +60 -52
  16. data/lib/authlogic/acts_as_authentic/base.rb +40 -26
  17. data/lib/authlogic/acts_as_authentic/email.rb +96 -32
  18. data/lib/authlogic/acts_as_authentic/logged_in_status.rb +36 -12
  19. data/lib/authlogic/acts_as_authentic/login.rb +114 -49
  20. data/lib/authlogic/acts_as_authentic/magic_columns.rb +17 -6
  21. data/lib/authlogic/acts_as_authentic/password.rb +296 -139
  22. data/lib/authlogic/acts_as_authentic/perishable_token.rb +34 -20
  23. data/lib/authlogic/acts_as_authentic/persistence_token.rb +20 -24
  24. data/lib/authlogic/acts_as_authentic/queries/find_with_case.rb +67 -0
  25. data/lib/authlogic/acts_as_authentic/restful_authentication.rb +68 -23
  26. data/lib/authlogic/acts_as_authentic/session_maintenance.rb +128 -85
  27. data/lib/authlogic/acts_as_authentic/single_access_token.rb +41 -25
  28. data/lib/authlogic/acts_as_authentic/validations_scope.rb +8 -8
  29. data/lib/authlogic/authenticates_many/association.rb +22 -14
  30. data/lib/authlogic/authenticates_many/base.rb +35 -16
  31. data/lib/authlogic/config.rb +10 -10
  32. data/lib/authlogic/controller_adapters/abstract_adapter.rb +40 -12
  33. data/lib/authlogic/controller_adapters/rack_adapter.rb +15 -8
  34. data/lib/authlogic/controller_adapters/rails_adapter.rb +42 -22
  35. data/lib/authlogic/controller_adapters/sinatra_adapter.rb +3 -3
  36. data/lib/authlogic/crypto_providers.rb +91 -0
  37. data/lib/authlogic/crypto_providers/aes256.rb +42 -14
  38. data/lib/authlogic/crypto_providers/bcrypt.rb +35 -20
  39. data/lib/authlogic/crypto_providers/md5.rb +11 -9
  40. data/lib/authlogic/crypto_providers/scrypt.rb +26 -13
  41. data/lib/authlogic/crypto_providers/sha1.rb +14 -8
  42. data/lib/authlogic/crypto_providers/sha256.rb +16 -12
  43. data/lib/authlogic/crypto_providers/sha512.rb +8 -24
  44. data/lib/authlogic/crypto_providers/wordpress.rb +44 -15
  45. data/lib/authlogic/i18n.rb +33 -20
  46. data/lib/authlogic/i18n/translator.rb +1 -1
  47. data/lib/authlogic/random.rb +12 -29
  48. data/lib/authlogic/regex.rb +59 -27
  49. data/lib/authlogic/session/activation.rb +36 -23
  50. data/lib/authlogic/session/active_record_trickery.rb +13 -10
  51. data/lib/authlogic/session/base.rb +20 -8
  52. data/lib/authlogic/session/brute_force_protection.rb +87 -56
  53. data/lib/authlogic/session/callbacks.rb +99 -49
  54. data/lib/authlogic/session/cookies.rb +128 -59
  55. data/lib/authlogic/session/existence.rb +29 -19
  56. data/lib/authlogic/session/foundation.rb +70 -16
  57. data/lib/authlogic/session/http_auth.rb +39 -31
  58. data/lib/authlogic/session/id.rb +27 -15
  59. data/lib/authlogic/session/klass.rb +17 -13
  60. data/lib/authlogic/session/magic_columns.rb +78 -59
  61. data/lib/authlogic/session/magic_states.rb +50 -27
  62. data/lib/authlogic/session/params.rb +79 -50
  63. data/lib/authlogic/session/password.rb +197 -118
  64. data/lib/authlogic/session/perishable_token.rb +12 -6
  65. data/lib/authlogic/session/persistence.rb +20 -14
  66. data/lib/authlogic/session/priority_record.rb +20 -16
  67. data/lib/authlogic/session/scopes.rb +63 -33
  68. data/lib/authlogic/session/session.rb +40 -25
  69. data/lib/authlogic/session/timeout.rb +51 -34
  70. data/lib/authlogic/session/unauthorized_record.rb +24 -18
  71. data/lib/authlogic/session/validation.rb +32 -21
  72. data/lib/authlogic/test_case.rb +123 -35
  73. data/lib/authlogic/test_case/mock_controller.rb +14 -13
  74. data/lib/authlogic/test_case/mock_cookie_jar.rb +14 -5
  75. data/lib/authlogic/test_case/mock_logger.rb +1 -1
  76. data/lib/authlogic/test_case/mock_request.rb +9 -4
  77. data/lib/authlogic/test_case/rails_request_adapter.rb +8 -7
  78. data/lib/authlogic/version.rb +21 -0
  79. data/test/acts_as_authentic_test/base_test.rb +1 -1
  80. data/test/acts_as_authentic_test/email_test.rb +80 -63
  81. data/test/acts_as_authentic_test/logged_in_status_test.rb +14 -8
  82. data/test/acts_as_authentic_test/login_test.rb +91 -49
  83. data/test/acts_as_authentic_test/magic_columns_test.rb +13 -13
  84. data/test/acts_as_authentic_test/password_test.rb +82 -60
  85. data/test/acts_as_authentic_test/perishable_token_test.rb +31 -25
  86. data/test/acts_as_authentic_test/persistence_token_test.rb +9 -5
  87. data/test/acts_as_authentic_test/restful_authentication_test.rb +18 -9
  88. data/test/acts_as_authentic_test/session_maintenance_test.rb +86 -22
  89. data/test/acts_as_authentic_test/single_access_test.rb +15 -15
  90. data/test/adapter_test.rb +21 -0
  91. data/test/authenticates_many_test.rb +26 -11
  92. data/test/config_test.rb +9 -9
  93. data/test/crypto_provider_test/aes256_test.rb +3 -3
  94. data/test/crypto_provider_test/bcrypt_test.rb +1 -1
  95. data/test/crypto_provider_test/scrypt_test.rb +2 -2
  96. data/test/crypto_provider_test/sha1_test.rb +4 -4
  97. data/test/crypto_provider_test/sha256_test.rb +2 -2
  98. data/test/crypto_provider_test/sha512_test.rb +3 -3
  99. data/test/crypto_provider_test/wordpress_test.rb +24 -0
  100. data/test/gemfiles/Gemfile.rails-4.2.x +2 -2
  101. data/test/gemfiles/Gemfile.rails-5.0.x +6 -0
  102. data/test/gemfiles/Gemfile.rails-5.1.x +6 -0
  103. data/test/gemfiles/Gemfile.rails-5.2.x +6 -0
  104. data/test/gemfiles/Gemfile.rails-master +6 -0
  105. data/test/i18n_test.rb +9 -9
  106. data/test/libs/affiliate.rb +2 -2
  107. data/test/libs/company.rb +4 -4
  108. data/test/libs/employee.rb +2 -2
  109. data/test/libs/employee_session.rb +1 -1
  110. data/test/libs/ldaper.rb +1 -1
  111. data/test/libs/project.rb +1 -1
  112. data/test/libs/user_session.rb +2 -2
  113. data/test/random_test.rb +9 -38
  114. data/test/session_test/activation_test.rb +7 -7
  115. data/test/session_test/active_record_trickery_test.rb +9 -6
  116. data/test/session_test/brute_force_protection_test.rb +26 -21
  117. data/test/session_test/callbacks_test.rb +10 -4
  118. data/test/session_test/cookies_test.rb +54 -20
  119. data/test/session_test/existence_test.rb +45 -23
  120. data/test/session_test/foundation_test.rb +17 -1
  121. data/test/session_test/http_auth_test.rb +11 -12
  122. data/test/session_test/id_test.rb +3 -3
  123. data/test/session_test/klass_test.rb +2 -2
  124. data/test/session_test/magic_columns_test.rb +15 -17
  125. data/test/session_test/magic_states_test.rb +17 -19
  126. data/test/session_test/params_test.rb +26 -20
  127. data/test/session_test/password_test.rb +11 -12
  128. data/test/session_test/perishability_test.rb +5 -5
  129. data/test/session_test/persistence_test.rb +4 -3
  130. data/test/session_test/scopes_test.rb +15 -9
  131. data/test/session_test/session_test.rb +7 -6
  132. data/test/session_test/timeout_test.rb +16 -14
  133. data/test/session_test/unauthorized_record_test.rb +3 -3
  134. data/test/session_test/validation_test.rb +5 -5
  135. data/test/test_helper.rb +115 -49
  136. metadata +107 -36
  137. data/README.rdoc +0 -232
  138. data/test/gemfiles/Gemfile.rails-3.2.x +0 -7
  139. data/test/gemfiles/Gemfile.rails-4.0.x +0 -7
  140. data/test/gemfiles/Gemfile.rails-4.1.x +0 -7
data/Rakefile CHANGED
@@ -1,13 +1,19 @@
1
- require 'rubygems'
2
- require 'bundler'
1
+ require "rubygems"
2
+ require "bundler"
3
3
 
4
4
  Bundler.setup
5
5
 
6
- require 'rake/testtask'
6
+ require "rake/testtask"
7
7
  Rake::TestTask.new(:test) do |test|
8
- test.libs << 'test'
9
- test.pattern = 'test/**/*_test.rb'
10
- test.verbose = true
8
+ test.libs << "test"
9
+ test.pattern = "test/**/*_test.rb"
10
+ test.verbose = false
11
+
12
+ # Set interpreter warning level to 2 (verbose)
13
+ test.ruby_opts += ["-W2"]
11
14
  end
12
15
 
13
- task :default => :test
16
+ require "rubocop/rake_task"
17
+ RuboCop::RakeTask.new
18
+
19
+ task default: %i[rubocop test]
@@ -0,0 +1,22 @@
1
+ # Upgrading Authlogic
2
+
3
+ Supplemental instructions to complement CHANGELOG.md.
4
+
5
+ ## 3.4.0
6
+
7
+ In version 3.4.0, released 2014-03-03, the default crypto_provider was changed
8
+ from *Sha512* to *SCrypt*.
9
+
10
+ If you never set a crypto_provider and are upgrading, your passwords will break
11
+ unless you specify `Sha512`.
12
+
13
+ ``` ruby
14
+ c.crypto_provider = Authlogic::CryptoProviders::Sha512
15
+ ```
16
+
17
+ And if you want to automatically upgrade from *Sha512* to *SCrypt* as users login:
18
+
19
+ ```ruby
20
+ c.transition_from_crypto_providers = [Authlogic::CryptoProviders::Sha512]
21
+ c.crypto_provider = Authlogic::CryptoProviders::SCrypt
22
+ ```
@@ -1,27 +1,38 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
1
+ require "English"
2
+ $LOAD_PATH.push File.expand_path("lib", __dir__)
3
+ require "authlogic/version"
3
4
 
4
- Gem::Specification.new do |s|
5
- s.name = "authlogic"
6
- s.version = "3.4.6"
7
- s.platform = Gem::Platform::RUBY
8
- s.authors = ["Ben Johnson"]
9
- s.email = ["bjohnson@binarylogic.com"]
10
- s.homepage = "http://github.com/binarylogic/authlogic"
11
- s.summary = %q{A clean, simple, and unobtrusive ruby authentication solution.}
12
- s.description = %q{A clean, simple, and unobtrusive ruby authentication solution.}
5
+ ::Gem::Specification.new do |s|
6
+ s.name = "authlogic"
7
+ s.version = ::Authlogic.gem_version.to_s
8
+ s.platform = ::Gem::Platform::RUBY
9
+ s.authors = [
10
+ "Ben Johnson",
11
+ "Tieg Zaharia",
12
+ "Jared Beck"
13
+ ]
14
+ s.email = [
15
+ "bjohnson@binarylogic.com",
16
+ "tieg.zaharia@gmail.com",
17
+ "jared@jaredbeck.com"
18
+ ]
19
+ s.homepage = "http://github.com/binarylogic/authlogic"
20
+ s.summary = "A clean, simple, and unobtrusive ruby authentication solution."
21
+ s.license = "MIT"
13
22
 
14
- s.license = 'MIT'
23
+ s.required_ruby_version = ">= 2.2.0"
24
+ s.add_dependency "activerecord", [">= 4.2", "< 5.3"]
25
+ s.add_dependency "activesupport", [">= 4.2", "< 5.3"]
26
+ s.add_dependency "request_store", "~> 1.0"
27
+ s.add_dependency "scrypt", ">= 1.2", "< 4.0"
28
+ s.add_development_dependency "bcrypt", "~> 3.1"
29
+ s.add_development_dependency "byebug", "~> 10.0"
30
+ s.add_development_dependency "minitest-reporters", "~> 1.3"
31
+ s.add_development_dependency "rubocop", "~> 0.58.1"
32
+ s.add_development_dependency "timecop", "~> 0.7"
15
33
 
16
- s.add_dependency 'activerecord', '>= 3.2'
17
- s.add_dependency 'activesupport', '>= 3.2'
18
- s.add_dependency 'request_store', '~> 1.0'
19
- s.add_dependency 'scrypt', '>= 1.2', '< 3.0'
20
- s.add_development_dependency 'bcrypt', '~> 3.1'
21
- s.add_development_dependency 'timecop', '~> 0.7'
22
-
23
- s.files = `git ls-files`.split("\n")
24
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
25
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
34
+ s.files = `git ls-files`.split("\n")
35
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
36
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
26
37
  s.require_paths = ["lib"]
27
38
  end
@@ -1,59 +1,67 @@
1
+ # Authlogic uses ActiveSupport's core extensions like `strip_heredoc` and
2
+ # `squish`. ActiveRecord does not `require` these exensions, so we must.
3
+ #
4
+ # It's possible that we could save a few milliseconds by loading only the
5
+ # specific core extensions we need, but `all.rb` is simpler. We can revisit this
6
+ # decision if it becomes a problem.
7
+ require "active_support/all"
8
+
1
9
  require "active_record"
2
10
 
3
11
  path = File.dirname(__FILE__) + "/authlogic/"
4
12
 
5
13
  [
6
- "i18n",
7
- "random",
8
- "regex",
9
- "config",
10
-
11
- "controller_adapters/abstract_adapter",
12
-
13
- "crypto_providers",
14
-
15
- "authenticates_many/base",
16
- "authenticates_many/association",
17
-
18
- "acts_as_authentic/email",
19
- "acts_as_authentic/logged_in_status",
20
- "acts_as_authentic/login",
21
- "acts_as_authentic/magic_columns",
22
- "acts_as_authentic/password",
23
- "acts_as_authentic/perishable_token",
24
- "acts_as_authentic/persistence_token",
25
- "acts_as_authentic/restful_authentication",
26
- "acts_as_authentic/session_maintenance",
27
- "acts_as_authentic/single_access_token",
28
- "acts_as_authentic/validations_scope",
29
- "acts_as_authentic/base",
30
-
31
- "session/activation",
32
- "session/active_record_trickery",
33
- "session/brute_force_protection",
34
- "session/callbacks",
35
- "session/cookies",
36
- "session/existence",
37
- "session/foundation",
38
- "session/http_auth",
39
- "session/id",
40
- "session/klass",
41
- "session/magic_columns",
42
- "session/magic_states",
43
- "session/params",
44
- "session/password",
45
- "session/perishable_token",
46
- "session/persistence",
47
- "session/priority_record",
48
- "session/scopes",
49
- "session/session",
50
- "session/timeout",
51
- "session/unauthorized_record",
52
- "session/validation",
53
- "session/base"
14
+ "i18n",
15
+ "random",
16
+ "regex",
17
+ "config",
18
+
19
+ "controller_adapters/abstract_adapter",
20
+
21
+ "crypto_providers",
22
+
23
+ "authenticates_many/base",
24
+ "authenticates_many/association",
25
+
26
+ "acts_as_authentic/email",
27
+ "acts_as_authentic/logged_in_status",
28
+ "acts_as_authentic/login",
29
+ "acts_as_authentic/magic_columns",
30
+ "acts_as_authentic/password",
31
+ "acts_as_authentic/perishable_token",
32
+ "acts_as_authentic/persistence_token",
33
+ "acts_as_authentic/restful_authentication",
34
+ "acts_as_authentic/session_maintenance",
35
+ "acts_as_authentic/single_access_token",
36
+ "acts_as_authentic/validations_scope",
37
+ "acts_as_authentic/base",
38
+
39
+ "session/activation",
40
+ "session/active_record_trickery",
41
+ "session/brute_force_protection",
42
+ "session/callbacks",
43
+ "session/cookies",
44
+ "session/existence",
45
+ "session/foundation",
46
+ "session/http_auth",
47
+ "session/id",
48
+ "session/klass",
49
+ "session/magic_columns",
50
+ "session/magic_states",
51
+ "session/params",
52
+ "session/password",
53
+ "session/perishable_token",
54
+ "session/persistence",
55
+ "session/priority_record",
56
+ "session/scopes",
57
+ "session/session",
58
+ "session/timeout",
59
+ "session/unauthorized_record",
60
+ "session/validation",
61
+ "session/base"
54
62
  ].each do |library|
55
- require path + library
56
- end
63
+ require path + library
64
+ end
57
65
 
58
- require path + "controller_adapters/rails_adapter" if defined?( Rails )
59
- require path + "controller_adapters/sinatra_adapter" if defined?( Sinatra )
66
+ require path + "controller_adapters/rails_adapter" if defined?(Rails)
67
+ require path + "controller_adapters/sinatra_adapter" if defined?(Sinatra)
@@ -11,9 +11,11 @@ module Authlogic
11
11
  end
12
12
  end
13
13
 
14
+ # The primary configuration of a model (often, `User`) for use with
15
+ # authlogic. These methods become class methods of ::ActiveRecord::Base.
14
16
  module Config
15
- # This includes a lot of helpful methods for authenticating records which The Authlogic::Session module relies on.
16
- # To use it just do:
17
+ # This includes a lot of helpful methods for authenticating records
18
+ # which the Authlogic::Session module relies on. To use it just do:
17
19
  #
18
20
  # class User < ActiveRecord::Base
19
21
  # acts_as_authentic
@@ -26,14 +28,16 @@ module Authlogic
26
28
  # end
27
29
  #
28
30
  # See the various sub modules for the configuration they provide.
29
- def acts_as_authentic(unsupported_options = nil, &block)
31
+ def acts_as_authentic(unsupported_options = nil)
30
32
  # Stop all configuration if the DB is not set up
31
- return if !db_setup?
33
+ return unless db_setup?
32
34
 
33
- if !unsupported_options.nil?
35
+ unless unsupported_options.nil?
34
36
  raise ArgumentError.new(
35
- "You are using the old v1.X.X configuration method for Authlogic. Instead of passing a hash of " +
36
- "configuration options to acts_as_authentic, pass a block: acts_as_authentic { |c| c.my_option = my_value }"
37
+ "You are using the old v1.X.X configuration method for " \
38
+ "Authlogic. Instead of passing a hash of configuration " \
39
+ "options to acts_as_authentic, pass a block: " \
40
+ "acts_as_authentic { |c| c.my_option = my_value }"
37
41
  )
38
42
  end
39
43
 
@@ -41,12 +45,15 @@ module Authlogic
41
45
  acts_as_authentic_modules.each { |mod| include mod }
42
46
  end
43
47
 
44
- # Since this part of Authlogic deals with another class, ActiveRecord, we can't just start including things
45
- # in ActiveRecord itself. A lot of these module includes need to be triggered by the acts_as_authentic method
46
- # call. For example, you don't want to start adding in email validations and what not into a model that has
47
- # nothing to do with Authlogic.
48
+ # Since this part of Authlogic deals with another class, ActiveRecord,
49
+ # we can't just start including things in ActiveRecord itself. A lot of
50
+ # these module includes need to be triggered by the acts_as_authentic
51
+ # method call. For example, you don't want to start adding in email
52
+ # validations and what not into a model that has nothing to do with
53
+ # Authlogic.
48
54
  #
49
- # That being said, this is your tool for extending Authlogic and "hooking" into the acts_as_authentic call.
55
+ # That being said, this is your tool for extending Authlogic and
56
+ # "hooking" into the acts_as_authentic call.
50
57
  def add_acts_as_authentic_module(mod, action = :append)
51
58
  modules = acts_as_authentic_modules.clone
52
59
  case action
@@ -59,7 +66,8 @@ module Authlogic
59
66
  self.acts_as_authentic_modules = modules
60
67
  end
61
68
 
62
- # This is the same as add_acts_as_authentic_module, except that it removes the module from the list.
69
+ # This is the same as add_acts_as_authentic_module, except that it
70
+ # removes the module from the list.
63
71
  def remove_acts_as_authentic_module(mod)
64
72
  modules = acts_as_authentic_modules.clone
65
73
  modules.delete(mod)
@@ -67,21 +75,24 @@ module Authlogic
67
75
  end
68
76
 
69
77
  private
70
- def db_setup?
71
- begin
72
- column_names
73
- true
74
- rescue Exception
75
- false
76
- end
77
- end
78
78
 
79
- def first_column_to_exist(*columns_to_check)
80
- if db_setup?
81
- columns_to_check.each { |column_name| return column_name.to_sym if column_names.include?(column_name.to_s) }
79
+ def db_setup?
80
+ column_names
81
+ true
82
+ rescue StandardError
83
+ false
84
+ end
85
+
86
+ def first_column_to_exist(*columns_to_check)
87
+ if db_setup?
88
+ columns_to_check.each do |column_name|
89
+ if column_names.include?(column_name.to_s)
90
+ return column_name.to_sym
91
+ end
82
92
  end
83
- columns_to_check.first && columns_to_check.first.to_sym
84
93
  end
94
+ columns_to_check.first && columns_to_check.first.to_sym
95
+ end
85
96
  end
86
97
  end
87
98
  end
@@ -95,8 +106,11 @@ end
95
106
  ::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::Password
96
107
  ::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::PerishableToken
97
108
  ::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::PersistenceToken
109
+
110
+ # RestfulAuthentication is deprecated. See comments in
111
+ # acts_as_authentic/restful_authentication.rb
98
112
  ::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::RestfulAuthentication
113
+
99
114
  ::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::SessionMaintenance
100
115
  ::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::SingleAccessToken
101
116
  ::ActiveRecord::Base.send :include, Authlogic::ActsAsAuthentic::ValidationsScope
102
-
@@ -1,9 +1,10 @@
1
1
  module Authlogic
2
2
  module ActsAsAuthentic
3
- # Sometimes models won't have an explicit "login" or "username" field. Instead they want to use the email field.
4
- # In this case, authlogic provides validations to make sure the email submited is actually a valid email. Don't worry,
5
- # if you do have a login or username field, Authlogic will still validate your email field. One less thing you have to
6
- # worry about.
3
+ # Sometimes models won't have an explicit "login" or "username" field.
4
+ # Instead they want to use the email field. In this case, authlogic provides
5
+ # validations to make sure the email submited is actually a valid email.
6
+ # Don't worry, if you do have a login or username field, Authlogic will
7
+ # still validate your email field. One less thing you have to worry about.
7
8
  module Email
8
9
  def self.included(klass)
9
10
  klass.class_eval do
@@ -32,67 +33,130 @@ module Authlogic
32
33
  end
33
34
  alias_method :validate_email_field=, :validate_email_field
34
35
 
35
- # A hash of options for the validates_length_of call for the email field. Allows you to change this however you want.
36
+ # A hash of options for the validates_length_of call for the email
37
+ # field. Allows you to change this however you want.
36
38
  #
37
- # <b>Keep in mind this is ruby. I wanted to keep this as flexible as possible, so you can completely replace the hash or
38
- # merge options into it. Checkout the convenience function merge_validates_length_of_email_field_options to merge
39
- # options.</b>
39
+ # <b>Keep in mind this is ruby. I wanted to keep this as flexible as
40
+ # possible, so you can completely replace the hash or merge options into
41
+ # it. Checkout the convenience function
42
+ # merge_validates_length_of_email_field_options to merge options.</b>
40
43
  #
41
44
  # * <tt>Default:</tt> {:maximum => 100}
42
45
  # * <tt>Accepts:</tt> Hash of options accepted by validates_length_of
43
46
  def validates_length_of_email_field_options(value = nil)
44
- rw_config(:validates_length_of_email_field_options, value, {:maximum => 100})
47
+ rw_config(:validates_length_of_email_field_options, value, maximum: 100)
45
48
  end
46
- alias_method :validates_length_of_email_field_options=, :validates_length_of_email_field_options
49
+ alias_method(
50
+ :validates_length_of_email_field_options=,
51
+ :validates_length_of_email_field_options
52
+ )
47
53
 
48
- # A convenience function to merge options into the validates_length_of_email_field_options. So intead of:
54
+ # A convenience function to merge options into the
55
+ # validates_length_of_email_field_options. So instead of:
49
56
  #
50
- # self.validates_length_of_email_field_options = validates_length_of_email_field_options.merge(:my_option => my_value)
57
+ # self.validates_length_of_email_field_options =
58
+ # validates_length_of_email_field_options.merge(:my_option => my_value)
51
59
  #
52
60
  # You can do this:
53
61
  #
54
62
  # merge_validates_length_of_email_field_options :my_option => my_value
55
63
  def merge_validates_length_of_email_field_options(options = {})
56
- self.validates_length_of_email_field_options = validates_length_of_email_field_options.merge(options)
64
+ self.validates_length_of_email_field_options =
65
+ validates_length_of_email_field_options.merge(options)
57
66
  end
58
67
 
59
- # A hash of options for the validates_format_of call for the email field. Allows you to change this however you want.
68
+ # A hash of options for the validates_format_of call for the email
69
+ # field. Allows you to change this however you want.
60
70
  #
61
- # <b>Keep in mind this is ruby. I wanted to keep this as flexible as possible, so you can completely replace the hash or
62
- # merge options into it. Checkout the convenience function merge_validates_format_of_email_field_options to merge
63
- # options.</b>
71
+ # <b>Keep in mind this is ruby. I wanted to keep this as flexible as
72
+ # possible, so you can completely replace the hash or merge options into
73
+ # it. Checkout the convenience function
74
+ # merge_validates_format_of_email_field_options to merge options.</b>
75
+ #
76
+ # To validate international email addresses, enable the provided
77
+ # alternate regex:
78
+ #
79
+ # ```
80
+ # validates_format_of_email_field_options(
81
+ # with: Authlogic::Regex.email_nonascii
82
+ # )
83
+ # ```
64
84
  #
65
- # To validate international email addresses, enable the provided alternate regex:
66
- # * <tt>validates_format_of_email_field_options({:with => Authlogic::Regex.email_nonascii})</tt>
85
+ # * <tt>Default:</tt>
86
+ #
87
+ # {
88
+ # :with => Authlogic::Regex.email,
89
+ # :message => Proc.new {
90
+ # I18n.t(
91
+ # 'error_messages.email_invalid',
92
+ # :default => "should look like an email address."
93
+ # )
94
+ # }
95
+ # }
67
96
  #
68
- # * <tt>Default:</tt> {:with => Authlogic::Regex.email, :message => Proc.new {I18n.t('error_messages.email_invalid', :default => "should look like an email address.")}}
69
97
  # * <tt>Accepts:</tt> Hash of options accepted by validates_format_of
70
98
  def validates_format_of_email_field_options(value = nil)
71
- rw_config(:validates_format_of_email_field_options, value, {:with => Authlogic::Regex.email, :message => Proc.new{I18n.t('error_messages.email_invalid', :default => "should look like an email address.")}})
99
+ rw_config(
100
+ :validates_format_of_email_field_options,
101
+ value,
102
+ with: Authlogic::Regex::EMAIL,
103
+ message: proc do
104
+ I18n.t(
105
+ "error_messages.email_invalid",
106
+ default: "should look like an email address."
107
+ )
108
+ end
109
+ )
72
110
  end
73
- alias_method :validates_format_of_email_field_options=, :validates_format_of_email_field_options
111
+ alias_method(
112
+ :validates_format_of_email_field_options=,
113
+ :validates_format_of_email_field_options
114
+ )
74
115
 
75
- # See merge_validates_length_of_email_field_options. The same thing except for validates_format_of_email_field_options.
116
+ # See merge_validates_length_of_email_field_options. The same thing
117
+ # except for validates_format_of_email_field_options.
76
118
  def merge_validates_format_of_email_field_options(options = {})
77
- self.validates_format_of_email_field_options = validates_format_of_email_field_options.merge(options)
119
+ self.validates_format_of_email_field_options =
120
+ validates_format_of_email_field_options.merge(options)
78
121
  end
79
122
 
80
- # A hash of options for the validates_uniqueness_of call for the email field. Allows you to change this however you want.
123
+ # A hash of options for the validates_uniqueness_of call for the email
124
+ # field. Allows you to change this however you want.
81
125
  #
82
- # <b>Keep in mind this is ruby. I wanted to keep this as flexible as possible, so you can completely replace the hash or
83
- # merge options into it. Checkout the convenience function merge_validates_uniqueness_of_email_field_options to merge
126
+ # <b>Keep in mind this is ruby. I wanted to keep this as flexible as
127
+ # possible, so you can completely replace the hash or merge options into
128
+ # it. Checkout the convenience function
129
+ # merge_validates_uniqueness_of_email_field_options to merge
84
130
  # options.</b>
85
131
  #
86
- # * <tt>Default:</tt> {:case_sensitive => false, :scope => validations_scope, :if => "#{email_field}_changed?".to_sym}
132
+ # * <tt>Default:</tt>
133
+ #
134
+ # {
135
+ # :case_sensitive => false,
136
+ # :scope => validations_scope,
137
+ # :if => "#{email_field}_changed?".to_sym
138
+ # }
139
+ #
87
140
  # * <tt>Accepts:</tt> Hash of options accepted by validates_uniqueness_of
88
141
  def validates_uniqueness_of_email_field_options(value = nil)
89
- rw_config(:validates_uniqueness_of_email_field_options, value, {:case_sensitive => false, :scope => validations_scope, :if => "#{email_field}_changed?".to_sym})
142
+ rw_config(
143
+ :validates_uniqueness_of_email_field_options,
144
+ value,
145
+ case_sensitive: false,
146
+ scope: validations_scope,
147
+ if: "#{email_field}_changed?".to_sym
148
+ )
90
149
  end
91
- alias_method :validates_uniqueness_of_email_field_options=, :validates_uniqueness_of_email_field_options
150
+ alias_method(
151
+ :validates_uniqueness_of_email_field_options=,
152
+ :validates_uniqueness_of_email_field_options
153
+ )
92
154
 
93
- # See merge_validates_length_of_email_field_options. The same thing except for validates_uniqueness_of_email_field_options.
155
+ # See merge_validates_length_of_email_field_options. The same thing
156
+ # except for validates_uniqueness_of_email_field_options.
94
157
  def merge_validates_uniqueness_of_email_field_options(options = {})
95
- self.validates_uniqueness_of_email_field_options = validates_uniqueness_of_email_field_options.merge(options)
158
+ self.validates_uniqueness_of_email_field_options =
159
+ validates_uniqueness_of_email_field_options.merge(options)
96
160
  end
97
161
  end
98
162