logical_model 0.3.1 → 0.3.2
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.
- data/VERSION +1 -1
- data/lib/typhoeus_fix/array_decoder.rb +93 -0
- data/logical_model.gemspec +2 -1
- metadata +3 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.2
|
@@ -0,0 +1,93 @@
|
|
1
|
+
#
|
2
|
+
# Typhoeus encodes arrays as hashes {'0' => v0, '1' => v1, .., 'n' => vN }
|
3
|
+
#
|
4
|
+
# To fix this in your rails server your should:
|
5
|
+
# in Gemfile:
|
6
|
+
# gem 'logical_model', '~> 0.3.2'
|
7
|
+
#
|
8
|
+
# in application_controller.rb:
|
9
|
+
#
|
10
|
+
# require 'typhoeus_fix/array_decoder'
|
11
|
+
# class ApplicationController < ActionController::Base
|
12
|
+
# include TyphoeusFix
|
13
|
+
# before_filter :decode_typhoeus_arrays
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
module TyphoeusFix
|
17
|
+
|
18
|
+
def decode_typhoeus_arrays
|
19
|
+
deep_decode(params)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Recursively decode Typhoeus encoded arrays
|
23
|
+
def deep_decode(hash)
|
24
|
+
return hash unless hash.is_a?(Hash)
|
25
|
+
hash.each_pair do |key,value|
|
26
|
+
if value.is_a?(Hash)
|
27
|
+
deep_decode(value)
|
28
|
+
hash[key] = value.decode_typhoeus_array
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Add Hash#is_typhoeus_array? method
|
35
|
+
class Hash
|
36
|
+
|
37
|
+
# Checks if hash is an Array encoded as a hash.
|
38
|
+
# Specifically will check for the hash to have this form: {'0' => v0, '1' => v1, .., 'n' => vN }
|
39
|
+
# @return [TrueClass]
|
40
|
+
def im_an_array_typhoeus_encoded?
|
41
|
+
return false if self.empty?
|
42
|
+
self.keys.sort == (0...self.keys.size).map{|i|i.to_s}
|
43
|
+
end
|
44
|
+
|
45
|
+
# If the hash is an array encoded by typhoeus an array is returned
|
46
|
+
# else the self is returned
|
47
|
+
#
|
48
|
+
# @see im_an_array_typhoeus_encoded?
|
49
|
+
#
|
50
|
+
# @return [Array/Hash]
|
51
|
+
def decode_typhoeus_array
|
52
|
+
if self.im_an_array_typhoeus_encoded?
|
53
|
+
Hash[self.sort].values
|
54
|
+
else
|
55
|
+
self
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
# Rack Middleware to fix Typhoeus arrays encoding
|
63
|
+
# TODO this middleware didn't work, when fixed use it and remove filter from ApplicationController
|
64
|
+
=begin
|
65
|
+
module Typhoeus
|
66
|
+
class ArraysDecoder
|
67
|
+
def initialize(app)
|
68
|
+
@app = app
|
69
|
+
end
|
70
|
+
|
71
|
+
def call(env)
|
72
|
+
|
73
|
+
params = env["action_dispatch.request.parameters"]
|
74
|
+
decode_typho_arrays(params)
|
75
|
+
env["action_dispatch.request.parameters"] = params
|
76
|
+
@app.call(env)
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
# Recursively decode Typhoeus encoded arrays
|
82
|
+
def decode_typho_arrays(hash)
|
83
|
+
return hash unless hash.is_a?(Hash)
|
84
|
+
hash.each_pair do |key,value|
|
85
|
+
if value.is_a?(Hash)
|
86
|
+
decode_typho_arrays(value)
|
87
|
+
hash[key] = value.decode_typhoeus_array
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
=end
|
data/logical_model.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "logical_model"
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Dwayne Macgowan"]
|
@@ -33,6 +33,7 @@ Gem::Specification.new do |s|
|
|
33
33
|
"db/migrate/001_create_users.rb",
|
34
34
|
"lib/logical_model.rb",
|
35
35
|
"lib/safe_log.rb",
|
36
|
+
"lib/typhoeus_fix/array_decoder.rb",
|
36
37
|
"logical_model.gemspec",
|
37
38
|
"models/user.rb",
|
38
39
|
"spec/client_spec.rb",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logical_model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -308,6 +308,7 @@ files:
|
|
308
308
|
- db/migrate/001_create_users.rb
|
309
309
|
- lib/logical_model.rb
|
310
310
|
- lib/safe_log.rb
|
311
|
+
- lib/typhoeus_fix/array_decoder.rb
|
311
312
|
- logical_model.gemspec
|
312
313
|
- models/user.rb
|
313
314
|
- spec/client_spec.rb
|
@@ -329,7 +330,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
329
330
|
version: '0'
|
330
331
|
segments:
|
331
332
|
- 0
|
332
|
-
hash:
|
333
|
+
hash: -154505059
|
333
334
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
334
335
|
none: false
|
335
336
|
requirements:
|