authlogic 4.0.1 → 4.1.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 (101) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +43 -1
  3. data/.rubocop_todo.yml +23 -132
  4. data/CHANGELOG.md +12 -0
  5. data/CONTRIBUTING.md +10 -3
  6. data/Gemfile +2 -2
  7. data/Rakefile +6 -6
  8. data/authlogic.gemspec +13 -12
  9. data/lib/authlogic/acts_as_authentic/base.rb +12 -7
  10. data/lib/authlogic/acts_as_authentic/email.rb +16 -6
  11. data/lib/authlogic/acts_as_authentic/logged_in_status.rb +10 -5
  12. data/lib/authlogic/acts_as_authentic/login.rb +11 -5
  13. data/lib/authlogic/acts_as_authentic/password.rb +111 -57
  14. data/lib/authlogic/acts_as_authentic/perishable_token.rb +6 -2
  15. data/lib/authlogic/acts_as_authentic/persistence_token.rb +1 -1
  16. data/lib/authlogic/acts_as_authentic/queries/find_with_case.rb +2 -2
  17. data/lib/authlogic/acts_as_authentic/restful_authentication.rb +31 -3
  18. data/lib/authlogic/acts_as_authentic/session_maintenance.rb +11 -3
  19. data/lib/authlogic/acts_as_authentic/single_access_token.rb +14 -2
  20. data/lib/authlogic/acts_as_authentic/validations_scope.rb +6 -6
  21. data/lib/authlogic/authenticates_many/association.rb +2 -2
  22. data/lib/authlogic/authenticates_many/base.rb +27 -19
  23. data/lib/authlogic/controller_adapters/rack_adapter.rb +1 -1
  24. data/lib/authlogic/controller_adapters/rails_adapter.rb +6 -3
  25. data/lib/authlogic/controller_adapters/sinatra_adapter.rb +2 -2
  26. data/lib/authlogic/crypto_providers.rb +2 -0
  27. data/lib/authlogic/crypto_providers/bcrypt.rb +15 -9
  28. data/lib/authlogic/crypto_providers/md5.rb +2 -1
  29. data/lib/authlogic/crypto_providers/scrypt.rb +12 -7
  30. data/lib/authlogic/crypto_providers/sha256.rb +2 -1
  31. data/lib/authlogic/crypto_providers/wordpress.rb +31 -2
  32. data/lib/authlogic/i18n.rb +22 -17
  33. data/lib/authlogic/regex.rb +57 -29
  34. data/lib/authlogic/session/activation.rb +1 -1
  35. data/lib/authlogic/session/brute_force_protection.rb +2 -2
  36. data/lib/authlogic/session/callbacks.rb +43 -36
  37. data/lib/authlogic/session/cookies.rb +4 -2
  38. data/lib/authlogic/session/existence.rb +1 -1
  39. data/lib/authlogic/session/foundation.rb +5 -1
  40. data/lib/authlogic/session/http_auth.rb +2 -2
  41. data/lib/authlogic/session/klass.rb +2 -1
  42. data/lib/authlogic/session/magic_columns.rb +4 -2
  43. data/lib/authlogic/session/magic_states.rb +9 -10
  44. data/lib/authlogic/session/params.rb +11 -4
  45. data/lib/authlogic/session/password.rb +72 -38
  46. data/lib/authlogic/session/perishable_token.rb +2 -1
  47. data/lib/authlogic/session/persistence.rb +2 -1
  48. data/lib/authlogic/session/scopes.rb +26 -16
  49. data/lib/authlogic/session/unauthorized_record.rb +12 -7
  50. data/lib/authlogic/session/validation.rb +1 -1
  51. data/lib/authlogic/test_case/mock_controller.rb +1 -1
  52. data/lib/authlogic/test_case/mock_cookie_jar.rb +1 -1
  53. data/lib/authlogic/test_case/mock_request.rb +1 -1
  54. data/lib/authlogic/version.rb +1 -1
  55. data/test/acts_as_authentic_test/base_test.rb +1 -1
  56. data/test/acts_as_authentic_test/email_test.rb +11 -11
  57. data/test/acts_as_authentic_test/logged_in_status_test.rb +4 -4
  58. data/test/acts_as_authentic_test/login_test.rb +2 -2
  59. data/test/acts_as_authentic_test/magic_columns_test.rb +1 -1
  60. data/test/acts_as_authentic_test/password_test.rb +1 -1
  61. data/test/acts_as_authentic_test/perishable_token_test.rb +2 -2
  62. data/test/acts_as_authentic_test/persistence_token_test.rb +1 -1
  63. data/test/acts_as_authentic_test/restful_authentication_test.rb +12 -3
  64. data/test/acts_as_authentic_test/session_maintenance_test.rb +1 -1
  65. data/test/acts_as_authentic_test/single_access_test.rb +1 -1
  66. data/test/adapter_test.rb +3 -3
  67. data/test/authenticates_many_test.rb +1 -1
  68. data/test/config_test.rb +9 -9
  69. data/test/crypto_provider_test/aes256_test.rb +1 -1
  70. data/test/crypto_provider_test/bcrypt_test.rb +1 -1
  71. data/test/crypto_provider_test/scrypt_test.rb +1 -1
  72. data/test/crypto_provider_test/sha1_test.rb +1 -1
  73. data/test/crypto_provider_test/sha256_test.rb +1 -1
  74. data/test/crypto_provider_test/sha512_test.rb +1 -1
  75. data/test/crypto_provider_test/wordpress_test.rb +24 -0
  76. data/test/i18n_test.rb +3 -3
  77. data/test/libs/user_session.rb +2 -2
  78. data/test/random_test.rb +1 -1
  79. data/test/session_test/activation_test.rb +1 -1
  80. data/test/session_test/active_record_trickery_test.rb +3 -3
  81. data/test/session_test/brute_force_protection_test.rb +1 -1
  82. data/test/session_test/callbacks_test.rb +9 -3
  83. data/test/session_test/cookies_test.rb +11 -11
  84. data/test/session_test/existence_test.rb +1 -1
  85. data/test/session_test/foundation_test.rb +1 -1
  86. data/test/session_test/http_auth_test.rb +6 -6
  87. data/test/session_test/id_test.rb +1 -1
  88. data/test/session_test/klass_test.rb +1 -1
  89. data/test/session_test/magic_columns_test.rb +1 -1
  90. data/test/session_test/magic_states_test.rb +1 -1
  91. data/test/session_test/params_test.rb +7 -4
  92. data/test/session_test/password_test.rb +1 -1
  93. data/test/session_test/perishability_test.rb +1 -1
  94. data/test/session_test/persistence_test.rb +1 -1
  95. data/test/session_test/scopes_test.rb +9 -3
  96. data/test/session_test/session_test.rb +2 -2
  97. data/test/session_test/timeout_test.rb +1 -1
  98. data/test/session_test/unauthorized_record_test.rb +1 -1
  99. data/test/session_test/validation_test.rb +1 -1
  100. data/test/test_helper.rb +34 -14
  101. metadata +6 -4
@@ -29,6 +29,8 @@ module Authlogic
29
29
  end
30
30
  end
31
31
 
32
+ # Configuration for the session maintenance aspect of acts_as_authentic.
33
+ # These methods become class methods of ::ActiveRecord::Base.
32
34
  module Config
33
35
  # In order to turn off automatic maintenance of sessions
34
36
  # after create, just set this to false.
@@ -68,12 +70,18 @@ module Authlogic
68
70
  # * <tt>Default:</tt> "#{klass.name}Session".constantize
69
71
  # * <tt>Accepts:</tt> Class
70
72
  def session_class(value = nil)
71
- const = "#{base_class.name}Session".constantize rescue nil
73
+ const = begin
74
+ "#{base_class.name}Session".constantize
75
+ rescue NameError
76
+ nil
77
+ end
72
78
  rw_config(:session_class, value, const)
73
79
  end
74
80
  alias_method :session_class=, :session_class
75
81
  end
76
82
 
83
+ # This module, as one of the `acts_as_authentic_modules`, is only included
84
+ # into an ActiveRecord model if that model calls `acts_as_authentic`.
77
85
  module Methods
78
86
  def self.included(klass)
79
87
  klass.class_eval do
@@ -139,7 +147,7 @@ module Authlogic
139
147
  session_id = session_ids.first
140
148
  session_class.create(*[self, self, session_id].compact)
141
149
 
142
- return true
150
+ true
143
151
  end
144
152
 
145
153
  def update_sessions
@@ -150,7 +158,7 @@ module Authlogic
150
158
  stale_session.save
151
159
  end
152
160
 
153
- return true
161
+ true
154
162
  end
155
163
 
156
164
  def session_ids
@@ -12,6 +12,8 @@ module Authlogic
12
12
  end
13
13
 
14
14
  # All configuration for the single_access token aspect of acts_as_authentic.
15
+ #
16
+ # These methods become class methods of ::ActiveRecord::Base.
15
17
  module Config
16
18
  # The single access token is used for authentication via URLs, such as a private
17
19
  # feed. That being said, if the user changes their password, that token probably
@@ -23,10 +25,16 @@ module Authlogic
23
25
  def change_single_access_token_with_password(value = nil)
24
26
  rw_config(:change_single_access_token_with_password, value, false)
25
27
  end
26
- alias_method :change_single_access_token_with_password=, :change_single_access_token_with_password
28
+ alias_method(
29
+ :change_single_access_token_with_password=,
30
+ :change_single_access_token_with_password
31
+ )
27
32
  end
28
33
 
29
34
  # All method, for the single_access token aspect of acts_as_authentic.
35
+ #
36
+ # This module, as one of the `acts_as_authentic_modules`, is only included
37
+ # into an ActiveRecord model if that model calls `acts_as_authentic`.
30
38
  module Methods
31
39
  def self.included(klass)
32
40
  return unless klass.column_names.include?("single_access_token")
@@ -36,11 +44,15 @@ module Authlogic
36
44
  validates_uniqueness_of :single_access_token, if: :single_access_token_changed?
37
45
  before_validation :reset_single_access_token, if: :reset_single_access_token?
38
46
  if respond_to?(:after_password_set)
39
- after_password_set(:reset_single_access_token, if: :change_single_access_token_with_password?)
47
+ after_password_set(
48
+ :reset_single_access_token,
49
+ if: :change_single_access_token_with_password?
50
+ )
40
51
  end
41
52
  end
42
53
  end
43
54
 
55
+ # :nodoc:
44
56
  module InstanceMethods
45
57
  # Resets the single_access_token to a random friendly token.
46
58
  def reset_single_access_token
@@ -1,8 +1,8 @@
1
1
  module Authlogic
2
2
  module ActsAsAuthentic
3
- # Allows you to scope everything to specific fields.
4
- # See the Config submodule for more info.
5
- # For information on how to scope off of a parent object see Authlogic::AuthenticatesMany
3
+ # Allows you to scope everything to specific fields. See the Config
4
+ # submodule for more info. For information on how to scope off of a parent
5
+ # object see Authlogic::AuthenticatesMany
6
6
  module ValidationsScope
7
7
  def self.included(klass)
8
8
  klass.class_eval do
@@ -12,9 +12,9 @@ module Authlogic
12
12
 
13
13
  # All configuration for the scope feature.
14
14
  module Config
15
- # Allows you to scope everything to specific field(s). Works just like validates_uniqueness_of.
16
- # For example, let's say a user belongs to a company, and you want to scope everything to the
17
- # company:
15
+ # Allows you to scope everything to specific field(s). Works just like
16
+ # validates_uniqueness_of. For example, let's say a user belongs to a
17
+ # company, and you want to scope everything to the company:
18
18
  #
19
19
  # acts_as_authentic do |c|
20
20
  # c.validations_scope = :company_id
@@ -29,8 +29,8 @@ module Authlogic
29
29
  self.id = id
30
30
  end
31
31
 
32
- [:create, :create!, :find, :new].each do |method|
33
- class_eval <<-EOS, __FILE__, __LINE__
32
+ %i[create create! find new].each do |method|
33
+ class_eval <<-EOS, __FILE__, __LINE__ + 1
34
34
  def #{method}(*args)
35
35
  klass.with_scope(scope_options) do
36
36
  klass.#{method}(*args)
@@ -17,8 +17,9 @@ module Authlogic
17
17
  # Checkout the authenticates_many method for a list of options.
18
18
  # You may also want to checkout Authlogic::ActsAsAuthentic::Scope to scope your model.
19
19
  module AuthenticatesMany
20
+ # These methods become class methods of ::ActiveRecord::Base.
20
21
  module Base
21
- # Allows you set essentially set up a relationship with your sessions. See module
22
+ # Allows you to set up a relationship with your sessions. See module
22
23
  # definition above for more details.
23
24
  #
24
25
  # === Options
@@ -26,35 +27,42 @@ module Authlogic
26
27
  # * <tt>session_class:</tt> default: "#{name}Session",
27
28
  # This is the related session class.
28
29
  #
29
- # * <tt>relationship_name:</tt> default: options[:session_class].klass_name.underscore.pluralize,
30
- # This is the name of the relationship you want to use to scope everything. For
31
- # example an Account has many Users. There should be a relationship called :users
32
- # that you defined with a has_many. The reason we use the relationship is so you
33
- # don't have to repeat yourself. The relationship could have all kinds of custom
34
- # options. So instead of repeating yourself we essentially use the scope that the
30
+ # * <tt>relationship_name:</tt>
31
+ # default: options[:session_class].klass_name.underscore.pluralize,
32
+ # This is the name of the relationship you want to use to scope
33
+ # everything. For example an Account has many Users. There should be a
34
+ # relationship called :users that you defined with a has_many. The
35
+ # reason we use the relationship is so you don't have to repeat
36
+ # yourself. The relationship could have all kinds of custom options. So
37
+ # instead of repeating yourself we essentially use the scope that the
35
38
  # relationship creates.
36
39
  #
37
40
  # * <tt>find_options:</tt> default: nil,
38
- # By default the find options are created from the relationship you specify with
39
- # :relationship_name. But if you want to override this and manually specify
40
- # find_options you can do it here. Specify options just as you would in
41
- # ActiveRecord::Base.find.
41
+ # By default the find options are created from the relationship you
42
+ # specify with :relationship_name. But if you want to override this and
43
+ # manually specify find_options you can do it here. Specify options just
44
+ # as you would in ActiveRecord::Base.find.
42
45
  #
43
46
  # * <tt>scope_cookies:</tt> default: false
44
- # By the nature of cookies they scope themselves if you are using subdomains to
45
- # access accounts. If you aren't using subdomains you need to have separate
46
- # cookies for each account, assuming a user is logging into more than one account.
47
- # Authlogic can take care of this for you by prefixing the name of the cookie and
48
- # session with the model id. Because it affects both cookies names and session keys,
49
- # the name `scope_cookies` is misleading. Perhaps simply `scope` or `scoped`
47
+ # By the nature of cookies they scope themselves if you are using
48
+ # subdomains to access accounts. If you aren't using subdomains you need
49
+ # to have separate cookies for each account, assuming a user is logging
50
+ # into more than one account. Authlogic can take care of this for you by
51
+ # prefixing the name of the cookie and session with the model id.
52
+ # Because it affects both cookies names and session keys, the name
53
+ # `scope_cookies` is misleading. Perhaps simply `scope` or `scoped`
50
54
  # would have been better.
51
55
  def authenticates_many(name, options = {})
52
56
  options[:session_class] ||= name.to_s.classify.constantize
53
57
  options[:relationship_name] ||= options[:session_class].klass_name.underscore.pluralize
54
- class_eval <<-EOS, __FILE__, __LINE__
58
+ class_eval <<-EOS, __FILE__, __LINE__ + 1
55
59
  def #{name}
56
60
  find_options = #{options[:find_options].inspect} || #{options[:relationship_name]}.where(nil)
57
- @#{name} ||= Authlogic::AuthenticatesMany::Association.new(#{options[:session_class]}, find_options, #{options[:scope_cookies] ? "self.class.model_name.name.underscore + '_' + self.send(self.class.primary_key).to_s" : "nil"})
61
+ @#{name} ||= Authlogic::AuthenticatesMany::Association.new(
62
+ #{options[:session_class]},
63
+ find_options,
64
+ #{options[:scope_cookies] ? "self.class.model_name.name.underscore + '_' + self.send(self.class.primary_key).to_s" : 'nil'}
65
+ )
58
66
  end
59
67
  EOS
60
68
  end
@@ -48,7 +48,7 @@ module Authlogic
48
48
  end
49
49
 
50
50
  def remote_ip
51
- self.ip
51
+ ip
52
52
  end
53
53
  end
54
54
 
@@ -1,4 +1,4 @@
1
- require 'action_controller'
1
+ require "action_controller"
2
2
 
3
3
  module Authlogic
4
4
  module ControllerAdapters
@@ -20,7 +20,7 @@ module Authlogic
20
20
  end
21
21
 
22
22
  def cookie_domain
23
- @cookie_domain_key ||= Rails::VERSION::STRING >= '2.3' ? :domain : :session_domain
23
+ @cookie_domain_key ||= Rails::VERSION::STRING >= "2.3" ? :domain : :session_domain
24
24
  controller.request.session_options[@cookie_domain_key]
25
25
  end
26
26
 
@@ -64,4 +64,7 @@ module Authlogic
64
64
  end
65
65
  end
66
66
 
67
- ActionController::Base.send(:include, Authlogic::ControllerAdapters::RailsAdapter::RailsImplementation)
67
+ ActionController::Base.send(
68
+ :include,
69
+ Authlogic::ControllerAdapters::RailsAdapter::RailsImplementation
70
+ )
@@ -32,7 +32,7 @@ module Authlogic
32
32
  end
33
33
 
34
34
  def session
35
- env['rack.session']
35
+ env["rack.session"]
36
36
  end
37
37
 
38
38
  def method_missing(meth, *args, &block)
@@ -42,7 +42,7 @@ module Authlogic
42
42
 
43
43
  class Adapter < AbstractAdapter
44
44
  def cookie_domain
45
- env['SERVER_NAME']
45
+ env["SERVER_NAME"]
46
46
  end
47
47
 
48
48
  module Implementation
@@ -7,5 +7,7 @@ module Authlogic
7
7
  autoload :BCrypt, "authlogic/crypto_providers/bcrypt"
8
8
  autoload :AES256, "authlogic/crypto_providers/aes256"
9
9
  autoload :SCrypt, "authlogic/crypto_providers/scrypt"
10
+ # crypto_providers/wordpress.rb has never been autoloaded, and now it is
11
+ # deprecated.
10
12
  end
11
13
  end
@@ -16,10 +16,18 @@ module Authlogic
16
16
  # require "benchmark"
17
17
  #
18
18
  # Benchmark.bm(18) do |x|
19
- # x.report("BCrypt (cost = 10:") { 100.times { BCrypt::Password.create("mypass", :cost => 10) } }
20
- # x.report("BCrypt (cost = 4:") { 100.times { BCrypt::Password.create("mypass", :cost => 4) } }
21
- # x.report("Sha512:") { 100.times { Digest::SHA512.hexdigest("mypass") } }
22
- # x.report("Sha1:") { 100.times { Digest::SHA1.hexdigest("mypass") } }
19
+ # x.report("BCrypt (cost = 10:") {
20
+ # 100.times { BCrypt::Password.create("mypass", :cost => 10) }
21
+ # }
22
+ # x.report("BCrypt (cost = 4:") {
23
+ # 100.times { BCrypt::Password.create("mypass", :cost => 4) }
24
+ # }
25
+ # x.report("Sha512:") {
26
+ # 100.times { Digest::SHA512.hexdigest("mypass") }
27
+ # }
28
+ # x.report("Sha1:") {
29
+ # 100.times { Digest::SHA1.hexdigest("mypass") }
30
+ # }
23
31
  # end
24
32
  #
25
33
  # user system total real
@@ -95,11 +103,9 @@ module Authlogic
95
103
  end
96
104
 
97
105
  def new_from_hash(hash)
98
- begin
99
- ::BCrypt::Password.new(hash)
100
- rescue ::BCrypt::Errors::InvalidHash
101
- return nil
102
- end
106
+ ::BCrypt::Password.new(hash)
107
+ rescue ::BCrypt::Errors::InvalidHash
108
+ nil
103
109
  end
104
110
  end
105
111
  end
@@ -24,7 +24,8 @@ module Authlogic
24
24
  digest
25
25
  end
26
26
 
27
- # Does the crypted password match the tokens? Uses the same tokens that were used to encrypt.
27
+ # Does the crypted password match the tokens? Uses the same tokens that
28
+ # were used to encrypt.
28
29
  def matches?(crypted, *tokens)
29
30
  encrypt(*tokens) == crypted
30
31
  end
@@ -19,7 +19,13 @@ module Authlogic
19
19
  # end
20
20
  class SCrypt
21
21
  class << self
22
- DEFAULTS = { key_len: 32, salt_size: 8, max_time: 0.2, max_mem: 1024 * 1024, max_memfrac: 0.5 }.freeze
22
+ DEFAULTS = {
23
+ key_len: 32,
24
+ salt_size: 8,
25
+ max_time: 0.2,
26
+ max_mem: 1024 * 1024,
27
+ max_memfrac: 0.5
28
+ }.freeze
23
29
 
24
30
  attr_writer :key_len, :salt_size, :max_time, :max_mem, :max_memfrac
25
31
  # Key length - length in bytes of generated key, from 16 to 512.
@@ -42,7 +48,8 @@ module Authlogic
42
48
  @max_mem ||= DEFAULTS[:max_mem]
43
49
  end
44
50
 
45
- # Max memory fraction - maximum memory out of all available. Always greater than zero and <= 0.5.
51
+ # Max memory fraction - maximum memory out of all available. Always
52
+ # greater than zero and <= 0.5.
46
53
  def max_memfrac
47
54
  @max_memfrac ||= DEFAULTS[:max_memfrac]
48
55
  end
@@ -73,11 +80,9 @@ module Authlogic
73
80
  end
74
81
 
75
82
  def new_from_hash(hash)
76
- begin
77
- ::SCrypt::Password.new(hash)
78
- rescue ::SCrypt::Errors::InvalidHash
79
- return nil
80
- end
83
+ ::SCrypt::Password.new(hash)
84
+ rescue ::SCrypt::Errors::InvalidHash
85
+ nil
81
86
  end
82
87
  end
83
88
  end
@@ -43,7 +43,8 @@ module Authlogic
43
43
  digest
44
44
  end
45
45
 
46
- # Does the crypted password match the tokens? Uses the same tokens that were used to encrypt.
46
+ # Does the crypted password match the tokens? Uses the same tokens that
47
+ # were used to encrypt.
47
48
  def matches?(crypted, *tokens)
48
49
  encrypt(*tokens) == crypted
49
50
  end
@@ -1,9 +1,38 @@
1
- require 'digest/md5'
1
+ require "digest/md5"
2
+
3
+ ::ActiveSupport::Deprecation.warn(
4
+ <<-EOS,
5
+ authlogic/crypto_providers/wordpress.rb is deprecated without replacement.
6
+ Yes, the entire file. Don't `require` it. Let us know ASAP if you are still
7
+ using it.
8
+
9
+ Reasons for deprecation: This file is not autoloaded by
10
+ `authlogic/crypto_providers.rb`. It's not documented. There are no tests.
11
+ So, it's likely used by a *very* small number of people, if any. It's never
12
+ had any contributions except by its original author, Jeffry Degrande, in
13
+ 2009. It is unclear why it should live in the main authlogic codebase. It
14
+ could be in a separate gem, authlogic-wordpress, or it could just live in
15
+ Jeffry's codebase, if he still even needs it, in 2018, nine years later.
16
+ EOS
17
+ caller(1)
18
+ )
19
+
2
20
  module Authlogic
3
21
  module CryptoProviders
22
+ # Crypto provider to transition from wordpress user accounts. Written by
23
+ # Jeffry Degrande in 2009. First released in 2.1.3.
24
+ #
25
+ # Problems:
26
+ #
27
+ # - There are no tests.
28
+ # - We can't even figure out how to run this without it crashing.
29
+ # - Presumably it implements some spec, but it doesn't mention which.
30
+ # - It is not documented anywhere.
31
+ # - There is no PR associated with this, and no discussion about it could be found.
32
+ #
4
33
  class Wordpress
5
34
  class << self
6
- ITOA64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.freeze
35
+ ITOA64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".freeze
7
36
 
8
37
  def matches?(crypted, *tokens)
9
38
  stretches = 1 << ITOA64.index(crypted[3, 1])
@@ -1,35 +1,40 @@
1
1
  require "authlogic/i18n/translator"
2
2
 
3
3
  module Authlogic
4
- # This class allows any message in Authlogic to use internationalization. In earlier
5
- # versions of Authlogic each message was translated via configuration. This cluttered up
6
- # the configuration and cluttered up Authlogic. So all translation has been extracted
7
- # out into this class. Now all messages pass through this class, making it much easier
8
- # to implement in I18n library / plugin you want. Use this as a layer that sits between
9
- # Authlogic and whatever I18n library you want to use.
4
+ # This class allows any message in Authlogic to use internationalization. In
5
+ # earlier versions of Authlogic each message was translated via configuration.
6
+ # This cluttered up the configuration and cluttered up Authlogic. So all
7
+ # translation has been extracted out into this class. Now all messages pass
8
+ # through this class, making it much easier to implement in I18n library /
9
+ # plugin you want. Use this as a layer that sits between Authlogic and
10
+ # whatever I18n library you want to use.
10
11
  #
11
- # By default this uses the rails I18n library, if it exists. If it doesn't exist it just
12
- # returns the default English message. The Authlogic I18n class works EXACTLY like the
13
- # rails I18n class. This is because the arguments are delegated to this class.
12
+ # By default this uses the rails I18n library, if it exists. If it doesn't
13
+ # exist it just returns the default English message. The Authlogic I18n class
14
+ # works EXACTLY like the rails I18n class. This is because the arguments are
15
+ # delegated to this class.
14
16
  #
15
17
  # Here is how all messages are translated internally with Authlogic:
16
18
  #
17
19
  # Authlogic::I18n.t('error_messages.password_invalid', :default => "is invalid")
18
20
  #
19
- # If you use a different I18n library just replace the build-in I18n::Translator class
20
- # with your own. For example:
21
+ # If you use a different I18n library just replace the build-in
22
+ # I18n::Translator class with your own. For example:
21
23
  #
22
24
  # class MyAuthlogicI18nTranslator
23
25
  # def translate(key, options = {})
24
- # # you will have key which will be something like: "error_messages.password_invalid"
25
- # # you will also have options[:default], which will be the default English version of the message
26
+ # # you will have key which will be something like:
27
+ # # "error_messages.password_invalid"
28
+ # # you will also have options[:default], which will be the default
29
+ # # English version of the message
26
30
  # # do whatever you want here with the arguments passed to you.
27
31
  # end
28
32
  # end
29
33
  #
30
34
  # Authlogic::I18n.translator = MyAuthlogicI18nTranslator.new
31
35
  #
32
- # That it's! Here is a complete list of the keys that are passed. Just define these however you wish:
36
+ # That it's! Here is a complete list of the keys that are passed. Just define
37
+ # these however you wish:
33
38
  #
34
39
  # authlogic:
35
40
  # error_messages:
@@ -81,9 +86,9 @@ module Authlogic
81
86
  @@translator = translator
82
87
  end
83
88
 
84
- # All message translation is passed to this method. The first argument is the key
85
- # for the message. The second is options, see the rails I18n library for a list of
86
- # options used.
89
+ # All message translation is passed to this method. The first argument is
90
+ # the key for the message. The second is options, see the rails I18n
91
+ # library for a list of options used.
87
92
  def translate(key, options = {})
88
93
  translator.translate key, { scope: I18n.scope }.merge(options)
89
94
  end