robot_catcher 0.0.3 → 0.0.5
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.
- checksums.yaml +8 -8
- data/README.md +1 -0
- data/lib/robot_catcher/helpers.rb +80 -76
- data/lib/robot_catcher/models.rb +1 -1
- data/lib/robot_catcher/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
Y2Q2YzM4OWY4YzYzYWZhYmVmNDMxMjkxM2U3ZDhmOWJiZmU4OWZjNQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YTA5NDE1YTQxY2Y2Yzc4NGUzMGQ2OTZkMDRmODU0MTUwNzM5OWJiYQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MzBjMDc3YTdlNTIzNzVjZDU2YWM1ZGNlODAxMWMyY2I5MmMzYjYzNzViZTAy
|
10
|
+
NzA0YTdmYzMxODk0ODE4YjBmZWMwZmIwMzM2NGU0YTdmYzg2ODRkNTgxYTk2
|
11
|
+
YTE3Mzg5MmZiNTY5NmFiN2U1ZGFjZjI0Y2IzNmViMzFlNmEzMmI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MTU4NGUzMmMxZTQ5OTExNWY3MmFiOTNjODE2Yzk2NDQ2MWE3YWI4MDZhZmQz
|
14
|
+
NDI3OWMyMDJhNzg1ODE3ZTU3MTU0NmM4ZTM2ZWFkNDZhZTZlYzFlNGQwZGJj
|
15
|
+
NzYxZTFjMjM0YzU5ZTNlZWRhMGU3MTg1MGYwYjc5ZWNkY2Y0MWU=
|
data/README.md
CHANGED
@@ -105,6 +105,7 @@ use `rc_form_for` like in the example above.
|
|
105
105
|
## UPCOMING NEXT
|
106
106
|
+ Store robot catches in database
|
107
107
|
+ Configuration (e.g. for a secret that is used for hashing)
|
108
|
+
+ Better usage of concerns
|
108
109
|
+ More [DRY](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself "Don't Repeat Yourself")
|
109
110
|
|
110
111
|
### To be considered
|
@@ -57,96 +57,100 @@ module RobotCatcher
|
|
57
57
|
# end # end
|
58
58
|
# RUBY_EVAL
|
59
59
|
# end
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
60
|
+
|
61
|
+
def rc_form_tag(url_for_options = {}, options = {}, &block)
|
62
|
+
if !options.has_key? :ip
|
63
|
+
raise ArgumentError, "should include ip address"
|
64
|
+
end
|
65
|
+
ip = options.delete(:ip)
|
66
|
+
|
67
|
+
timestamp = Time.now.to_i.to_s
|
68
|
+
# p "To be spinned (front-end): #{timestamp}#{ip}robotcatcher"
|
69
|
+
@spinner = Digest::MD5.hexdigest(timestamp + ip.to_s + "robotcatcher")
|
70
|
+
|
71
|
+
options[:spinner] = @spinner
|
72
|
+
|
73
|
+
html_options = options[:html] ||= {}
|
74
|
+
|
75
|
+
html_options[:data] = options.delete(:data) if options.has_key?(:data)
|
76
|
+
html_options[:remote] = options.delete(:remote) if options.has_key?(:remote)
|
77
|
+
html_options[:method] = options.delete(:method) if options.has_key?(:method)
|
78
|
+
html_options[:enforce_utf8] = options.delete(:enforce_utf8) if options.has_key?(:enforce_utf8)
|
79
|
+
html_options[:authenticity_token] = options.delete(:authenticity_token)
|
80
|
+
|
81
|
+
builder = RobotCatcher::Helpers::FormBuilder.new(nil, nil, self, options)
|
82
|
+
content = capture(builder, &block)
|
83
|
+
html_options[:multipart] ||= builder.multipart?
|
84
|
+
|
85
|
+
html_options = html_options_for_form(url_for_options, html_options)
|
86
|
+
|
87
|
+
if block_given?
|
88
|
+
output = form_tag_html(html_options)
|
89
|
+
output.safe_concat(hidden_field_tag(:timestamp, timestamp))
|
90
|
+
output.safe_concat(hidden_field_tag(:spinner, @spinner))
|
91
|
+
output << content
|
92
|
+
output.safe_concat("</form>")
|
93
|
+
else
|
94
|
+
output = form_tag_html(html_options)
|
95
|
+
output.safe_concat(hidden_field_tag(:timestamp, timestamp))
|
96
|
+
output.safe_concat(hidden_field_tag(:spinner, @spinner))
|
97
|
+
end
|
65
98
|
end
|
66
|
-
|
67
|
-
|
68
|
-
timestamp = Time.now.to_i.to_s
|
69
|
-
# p "To be spinned (front-end): #{timestamp}#{ip}robotcatcher"
|
70
|
-
@spinner = Digest::MD5.hexdigest(timestamp + ip.to_s + "robotcatcher")
|
99
|
+
end
|
100
|
+
end
|
71
101
|
|
72
|
-
|
102
|
+
module FormHelper
|
103
|
+
extend ActiveSupport::Concern
|
73
104
|
|
74
|
-
|
105
|
+
included do
|
106
|
+
def rc_form_for(record, *args, &block)
|
107
|
+
options = args.extract_options!
|
108
|
+
if !options.has_key? :ip
|
109
|
+
raise ArgumentError, "should include ip address"
|
110
|
+
end
|
111
|
+
ip = options.delete(:ip)
|
112
|
+
|
113
|
+
timestamp = Time.now.to_i.to_s
|
114
|
+
# p "To be spinned (front-end): #{timestamp}#{ip}robotcatcher"
|
115
|
+
spinner = Digest::MD5.hexdigest(timestamp + ip.to_s + "robotcatcher")
|
116
|
+
|
117
|
+
options[:spinner] = spinner
|
118
|
+
|
119
|
+
raise ArgumentError, "Missing block" unless block_given?
|
120
|
+
html_options = options[:html] ||= {}
|
121
|
+
|
122
|
+
case record
|
123
|
+
when String, Symbol
|
124
|
+
object_name = record
|
125
|
+
object = nil
|
126
|
+
else
|
127
|
+
object = record.is_a?(Array) ? record.last : record
|
128
|
+
raise ArgumentError, "First argument in form cannot contain nil or be empty" unless object
|
129
|
+
object_name = options[:as] || object.class.name.downcase
|
130
|
+
apply_form_for_options!(record, options)
|
131
|
+
end
|
75
132
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
133
|
+
html_options[:data] = options.delete(:data) if options.has_key?(:data)
|
134
|
+
html_options[:remote] = options.delete(:remote) if options.has_key?(:remote)
|
135
|
+
html_options[:method] = options.delete(:method) if options.has_key?(:method)
|
136
|
+
html_options[:enforce_utf8] = options.delete(:enforce_utf8) if options.has_key?(:enforce_utf8)
|
137
|
+
html_options[:authenticity_token] = options.delete(:authenticity_token)
|
81
138
|
|
82
|
-
|
83
|
-
|
84
|
-
|
139
|
+
builder = RobotCatcher::Helpers::FormBuilder.new(object_name, object, self, options)
|
140
|
+
content = capture(builder, &block)
|
141
|
+
html_options[:multipart] ||= builder.multipart?
|
85
142
|
|
86
|
-
|
87
|
-
|
88
|
-
if block_given?
|
143
|
+
html_options = html_options_for_form(options[:url] || {}, html_options)
|
144
|
+
|
89
145
|
output = form_tag_html(html_options)
|
90
146
|
output.safe_concat(hidden_field_tag(:timestamp, timestamp))
|
91
|
-
output.safe_concat(hidden_field_tag(:spinner,
|
147
|
+
output.safe_concat(hidden_field_tag(:spinner, spinner))
|
92
148
|
output << content
|
93
149
|
output.safe_concat("</form>")
|
94
|
-
else
|
95
|
-
output = form_tag_html(html_options)
|
96
|
-
output.safe_concat(hidden_field_tag(:timestamp, timestamp))
|
97
|
-
output.safe_concat(hidden_field_tag(:spinner, @spinner))
|
98
150
|
end
|
99
151
|
end
|
100
152
|
end
|
101
153
|
|
102
|
-
module FormHelper
|
103
|
-
def rc_form_for(record, *args, &block)
|
104
|
-
options = args.extract_options!
|
105
|
-
if !options.has_key? :ip
|
106
|
-
raise ArgumentError, "should include ip address"
|
107
|
-
end
|
108
|
-
ip = options.delete(:ip)
|
109
|
-
|
110
|
-
timestamp = Time.now.to_i.to_s
|
111
|
-
# p "To be spinned (front-end): #{timestamp}#{ip}robotcatcher"
|
112
|
-
spinner = Digest::MD5.hexdigest(timestamp + ip.to_s + "robotcatcher")
|
113
|
-
|
114
|
-
options[:spinner] = spinner
|
115
|
-
|
116
|
-
raise ArgumentError, "Missing block" unless block_given?
|
117
|
-
html_options = options[:html] ||= {}
|
118
|
-
|
119
|
-
case record
|
120
|
-
when String, Symbol
|
121
|
-
object_name = record
|
122
|
-
object = nil
|
123
|
-
else
|
124
|
-
object = record.is_a?(Array) ? record.last : record
|
125
|
-
raise ArgumentError, "First argument in form cannot contain nil or be empty" unless object
|
126
|
-
object_name = options[:as] || object.class.name.downcase
|
127
|
-
apply_form_for_options!(record, options)
|
128
|
-
end
|
129
|
-
|
130
|
-
html_options[:data] = options.delete(:data) if options.has_key?(:data)
|
131
|
-
html_options[:remote] = options.delete(:remote) if options.has_key?(:remote)
|
132
|
-
html_options[:method] = options.delete(:method) if options.has_key?(:method)
|
133
|
-
html_options[:enforce_utf8] = options.delete(:enforce_utf8) if options.has_key?(:enforce_utf8)
|
134
|
-
html_options[:authenticity_token] = options.delete(:authenticity_token)
|
135
|
-
|
136
|
-
builder = RobotCatcher::Helpers::FormBuilder.new(object_name, object, self, options)
|
137
|
-
content = capture(builder, &block)
|
138
|
-
html_options[:multipart] ||= builder.multipart?
|
139
|
-
|
140
|
-
html_options = html_options_for_form(options[:url] || {}, html_options)
|
141
|
-
|
142
|
-
output = form_tag_html(html_options)
|
143
|
-
output.safe_concat(hidden_field_tag(:timestamp, timestamp))
|
144
|
-
output.safe_concat(hidden_field_tag(:spinner, spinner))
|
145
|
-
output << content
|
146
|
-
output.safe_concat("</form>")
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
154
|
end
|
151
155
|
end
|
152
156
|
|
data/lib/robot_catcher/models.rb
CHANGED