humanizer 2.6.3 → 2.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: be89ceea477e5f5e5c498ff5306aad19e6317a8b
4
- data.tar.gz: 1aaba686fc42c26228e4bbd4562e346d68a86808
2
+ SHA256:
3
+ metadata.gz: b268345d6d2c138180c0524c04609775fa7bbd52741661fd4b23879be4eb6c9a
4
+ data.tar.gz: 9eb10255a421623d61b2ce64e9ec47674ad6409285db530362f75d56e66850c5
5
5
  SHA512:
6
- metadata.gz: 3ec3a319a7e009e8ef822abdbb40b7c162d0278770af14a89ab2db93d0da2a71d8560c67a41c20487ef9400680bf1c2b8da3fdb1cf75dd07924afea803ca76c7
7
- data.tar.gz: 19e2fda87d29a6c67f8d6a1f39437a3fb9826709848d671b955d89e7ce0839e7df780f01ab1ea6614c5143091983482a1ac494c0a7fc7c424cbbeaedf2035c60
6
+ metadata.gz: be4b6b44404226559c6a0e44fa97200408cfb40560e12d818bd6e79d6dbda8704acdb8dd7bca243fc0dfb6c3ccb970bad3ac6ed5057d0b1a523e8d795b555144
7
+ data.tar.gz: b5644e9aec6361012880742613db454a691c6b2fa0bd7eb7844565490c4c2d0d4104588e3a9237201ef720dfb5b4e8e67383adb459f530eeb0592b5502e5a171
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ### Humanizer 2.6.4 (2017-07-07)
2
+
3
+ * Prevents NoMethodError when form posts non-existing question id
4
+
1
5
  ### Humanizer 2.6.3 (2016-09-07)
2
6
 
3
7
  * Added translations: Danish, Serbian & Swedish
data/README.md CHANGED
@@ -1,13 +1,13 @@
1
1
  # Humanizer
2
2
 
3
- Humanizer is a very simple CAPTCHA method. It has a localized YAML file with questions and answers which is used to validate that the user is an actual human. Any model that includes ActiveModel::Validations should work. Our aim is to be database and mapper agnostic, so if it doesn't work for you, open an issue. Humanizer works with Rails 3 and 4.
3
+ Humanizer is a very simple CAPTCHA method. It has a localized YAML file with questions and answers which is used to validate that the user is an actual human. Any model that includes ActiveModel::Validations should work. Our aim is to be database and mapper agnostic, so if it doesn't work for you, open an issue. Humanizer works with Rails 3–7.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  Add `humanizer` to your Gemfile:
8
8
 
9
9
  ```ruby
10
- gem 'humanizer'
10
+ gem "humanizer"
11
11
  ```
12
12
 
13
13
  Bundle and run the generator in terminal:
@@ -60,7 +60,7 @@ You can just have a simple attribute on your model and use it to bypass the vali
60
60
 
61
61
  ```ruby
62
62
  attr_accessor :bypass_humanizer
63
- require_human_on :create, :unless => :bypass_humanizer
63
+ require_human_on :create, unless: :bypass_humanizer
64
64
  ```
65
65
 
66
66
  Now when bypass_humanizer is true, validation will be skipped.
@@ -75,11 +75,6 @@ To make sure the current question doesn't get asked again, you can pass the curr
75
75
  @user.change_humanizer_question(params[:user][:humanizer_question_id])
76
76
  ```
77
77
 
78
- ## Live sites
79
-
80
- * [ArcticStartup.com](http://arcticstartup.com/) - sign up form
81
- * [Paspartout](http://paspartout.com/) - sign up form
82
-
83
78
  ## License
84
79
 
85
80
  Humanizer is licensed under the MIT License, for more details see the LICENSE file.
data/bin/rake ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rake' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rake", "rake")
@@ -1,3 +1,3 @@
1
1
  module Humanizer
2
- VERSION = "2.6.3"
2
+ VERSION = "2.7.0"
3
3
  end
data/lib/humanizer.rb CHANGED
@@ -1,29 +1,28 @@
1
1
  module Humanizer
2
-
2
+
3
3
  def self.included(base)
4
4
  base.extend(ClassMethods)
5
5
  end
6
-
6
+
7
7
  attr_accessor :humanizer_answer
8
8
  attr_writer :humanizer_question_id
9
9
 
10
10
  def humanizer_question
11
11
  humanizer_questions[humanizer_question_id.to_i]["question"]
12
12
  end
13
-
13
+
14
14
  def humanizer_question_id
15
- @humanizer_question_id ||= random_humanizer_question_id
15
+ (@humanizer_question_id ||= random_humanizer_question_id).to_i
16
16
  end
17
-
17
+
18
18
  def change_humanizer_question(current=nil)
19
19
  @humanizer_question_ids = nil if humanizer_question_ids.compact.count == 1
20
20
  humanizer_question_ids.delete(current) if current
21
21
  @humanizer_question_id = random_humanizer_question_id
22
22
  end
23
-
23
+
24
24
  def humanizer_correct_answer?
25
- humanizer_answer &&
26
- humanizer_answers_for_id(humanizer_question_id).include?(humanizer_answer.mb_chars.downcase.strip)
25
+ humanizer_answer && humanizer_answers_for_id(humanizer_question_id).include?(humanizer_answer.mb_chars.downcase.strip)
27
26
  end
28
27
 
29
28
  private
@@ -33,14 +32,15 @@ module Humanizer
33
32
  questions = I18n.translate!("humanizer.questions")
34
33
  # Poor man's HashWithIndifferentAccess
35
34
  questions.map do |question|
36
- question.default_proc = proc do |h, k|
37
- case k
38
- when String then sym = k.to_sym; h[sym] if h.key?(sym)
39
- when Symbol then str = k.to_s; h[str] if h.key?(str)
40
- end
35
+ config = Hash.new
36
+ config.default_proc = proc do |h, k|
37
+ case k
38
+ when String then sym = k.to_sym; h[sym] if h.key?(sym)
39
+ when Symbol then str = k.to_s; h[str] if h.key?(str)
40
+ end
41
41
  end
42
+ config.merge(question)
42
43
  end
43
- questions
44
44
  end
45
45
  end
46
46
 
@@ -54,20 +54,23 @@ module Humanizer
54
54
 
55
55
  def humanizer_answers_for_id(id)
56
56
  question = humanizer_questions[id.to_i]
57
+
58
+ return [] unless question
59
+
57
60
  Array(question["answer"] || question["answers"]).map { |a| a.to_s.mb_chars.downcase }
58
61
  end
59
62
 
60
63
  def humanizer_check_answer
61
64
  errors.add(:humanizer_answer, I18n.translate("humanizer.validation.error")) unless humanizer_correct_answer?
62
65
  end
63
-
66
+
64
67
  module ClassMethods
65
-
68
+
66
69
  def require_human_on(validate_on = nil, opts = {})
67
70
  opts[:on] = validate_on if validate_on
68
71
  validate :humanizer_check_answer, opts
69
72
  end
70
-
73
+
71
74
  end
72
-
75
+
73
76
  end
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: humanizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.3
4
+ version: 2.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antti Akonniemi
8
8
  - Joao Carlos Cardoso
9
9
  - Matias Korhonen
10
10
  - Vesa Vänskä
11
- autorequire:
11
+ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2016-09-06 00:00:00.000000000 Z
14
+ date: 2023-06-19 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler
@@ -47,14 +47,14 @@ dependencies:
47
47
  requirements:
48
48
  - - "~>"
49
49
  - !ruby/object:Gem::Version
50
- version: 2.14.0
50
+ version: 3.6.0
51
51
  type: :development
52
52
  prerelease: false
53
53
  version_requirements: !ruby/object:Gem::Requirement
54
54
  requirements:
55
55
  - - "~>"
56
56
  - !ruby/object:Gem::Version
57
- version: 2.14.0
57
+ version: 3.6.0
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: activemodel
60
60
  requirement: !ruby/object:Gem::Requirement
@@ -82,6 +82,7 @@ files:
82
82
  - CHANGELOG.md
83
83
  - LICENSE
84
84
  - README.md
85
+ - bin/rake
85
86
  - lib/generators/humanizer_generator.rb
86
87
  - lib/generators/templates/locales/da.yml
87
88
  - lib/generators/templates/locales/de.yml
@@ -108,7 +109,7 @@ homepage: http://github.com/kiskolabs/humanizer
108
109
  licenses:
109
110
  - MIT
110
111
  metadata: {}
111
- post_install_message:
112
+ post_install_message:
112
113
  rdoc_options: []
113
114
  require_paths:
114
115
  - lib
@@ -123,9 +124,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
124
  - !ruby/object:Gem::Version
124
125
  version: 1.3.6
125
126
  requirements: []
126
- rubyforge_project: humanizer
127
- rubygems_version: 2.4.5.1
128
- signing_key:
127
+ rubygems_version: 3.1.2
128
+ signing_key:
129
129
  specification_version: 4
130
130
  summary: A really simple captcha solution
131
131
  test_files: []