humanizer 2.6.4 → 2.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +4 -0
- data/README.md +39 -0
- data/lib/humanizer/version.rb +1 -1
- data/lib/humanizer.rb +6 -7
- data/lib/humanizer_helper.rb +17 -0
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: df124f5def849dfe6dcfa45fc2916568e2d05a7f7250c499136cc1aa8fa27fcf
|
4
|
+
data.tar.gz: 00aded9be9984c9efd2ae3196841f27559e17b833f5fd8cd3b6de88473c451df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06f1ebf7066bebe4c2abf355a8f4efb4cbf6cfc8dde621b55a59b35e5e6d037ff04cfd9b19988741755d95902be47bb7caa39c035ddf9e010e5cc92efa481cfd
|
7
|
+
data.tar.gz: 5089521d758905893cbd21a054d6b14e7247098e03d725b124801f77b12d37396541270d29aa9b7d49b8e4f0496d82e89b6aa01b1b34c1423f7c5bbd4a83ce51
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
### Humanizer 2.7.1 (2024-12-19)
|
2
|
+
|
3
|
+
* Adds HumanizerHelper class for use cases when developers don't have a class they want to include Humanizer on(basic contact form for example)
|
4
|
+
|
1
5
|
### Humanizer 2.6.4 (2017-07-07)
|
2
6
|
|
3
7
|
* Prevents NoMethodError when form posts non-existing question id
|
data/README.md
CHANGED
@@ -46,6 +46,44 @@ end
|
|
46
46
|
|
47
47
|
4. If you are using strong_parameters, remember to permit `:humanizer_answer` and `:humanizer_question_id`.
|
48
48
|
|
49
|
+
## Usage without a model
|
50
|
+
|
51
|
+
Alternatively, you many use the built in HumanizerHelper class instead of using your own model (useful for something like a contact form if you don't have a model/class for this). Behavior is the same including `Humanizer` on a model, but all setters are available as optional arguments when initializing a HumanizerHelper instance.
|
52
|
+
|
53
|
+
1. Example initialization code(controller):
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
@humanizer_helper = HumanizerHelper.new
|
57
|
+
```
|
58
|
+
|
59
|
+
2. Example rails form usage:
|
60
|
+
|
61
|
+
```erb
|
62
|
+
<%= label_tag :humanizer_answer, @humanizer_helper.humanizer_question %>
|
63
|
+
<%= text_field_tag :humanizer_answer %>
|
64
|
+
<%= hidden_field_tag :humanizer_question_id, @humanizer_helper.humanizer_question_id %>
|
65
|
+
```
|
66
|
+
|
67
|
+
3. Example response handling:
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
humanizer_helper = HumanizerHelper.new(humanizer_answer: params[:humanizer_answer], humanizer_question_id: params[:humanizer_question_id])
|
71
|
+
if humanizer_helper.humanizer_correct_answer?
|
72
|
+
do_stuff
|
73
|
+
end
|
74
|
+
```
|
75
|
+
|
76
|
+
## Testing
|
77
|
+
|
78
|
+
A HumanizerHelper instance provides an additional `get_correct_humanizer_answer` method to make testing easier. Example:
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
question_id = find('#humanizer_question_id', visible: false).value #gets humanizer question id from example form above
|
82
|
+
humanizer_helper = HumanizerHelper.new(humanizer_question_id: question_id)
|
83
|
+
fill_in 'humanizer_answer', with: humanizer_helper.get_correct_humanizer_answer #fills in answer field from example above with the correct answer
|
84
|
+
```
|
85
|
+
|
86
|
+
|
49
87
|
## Configuration
|
50
88
|
|
51
89
|
Default translations can be found in config/locales/
|
@@ -102,6 +140,7 @@ Humanizer is licensed under the MIT License, for more details see the LICENSE fi
|
|
102
140
|
* [seogrady](https://github.com/seogrady)
|
103
141
|
* [yairgo](https://github.com/yairgo)
|
104
142
|
* [woto](https://github.com/woto)
|
143
|
+
* [Calvin Delamere](https://github.com/elbartostrikesagain)
|
105
144
|
|
106
145
|
## CI Build Status
|
107
146
|
|
data/lib/humanizer/version.rb
CHANGED
data/lib/humanizer.rb
CHANGED
@@ -30,16 +30,15 @@ module Humanizer
|
|
30
30
|
def humanizer_questions
|
31
31
|
@humanizer_questions ||= begin
|
32
32
|
questions = I18n.translate!("humanizer.questions")
|
33
|
-
#
|
33
|
+
# Create new mutable copies of the questions with indifferent access
|
34
34
|
questions.map do |question|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
end
|
35
|
+
new_hash = {}
|
36
|
+
question.each do |k, v|
|
37
|
+
new_hash[k.to_s] = v # Store everything with string keys
|
38
|
+
new_hash[k.to_sym] = v # Store everything with symbol keys
|
40
39
|
end
|
40
|
+
new_hash
|
41
41
|
end
|
42
|
-
questions
|
43
42
|
end
|
44
43
|
end
|
45
44
|
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class HumanizerHelper
|
2
|
+
include ActiveModel::Validations
|
3
|
+
include Humanizer
|
4
|
+
|
5
|
+
def initialize(options={})
|
6
|
+
options[:humanizer_question_id] = options[:humanizer_question_id].to_i unless options[:humanizer_question_id].nil?
|
7
|
+
options.each do |k, v|
|
8
|
+
self.send("#{k}=", v)
|
9
|
+
end
|
10
|
+
|
11
|
+
humanizer_question_id
|
12
|
+
end
|
13
|
+
|
14
|
+
def get_correct_humanizer_answer
|
15
|
+
humanizer_answers_for_id(humanizer_question_id.to_i)[0]
|
16
|
+
end
|
17
|
+
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.
|
4
|
+
version: 2.7.1
|
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:
|
14
|
+
date: 2024-12-19 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|
@@ -104,11 +104,12 @@ files:
|
|
104
104
|
- lib/generators/templates/locales/zh-TW.yml
|
105
105
|
- lib/humanizer.rb
|
106
106
|
- lib/humanizer/version.rb
|
107
|
+
- lib/humanizer_helper.rb
|
107
108
|
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
|
-
|
127
|
-
|
128
|
-
signing_key:
|
127
|
+
rubygems_version: 3.5.16
|
128
|
+
signing_key:
|
129
129
|
specification_version: 4
|
130
130
|
summary: A really simple captcha solution
|
131
131
|
test_files: []
|