active_job-arguments_plus 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/active_job/arguments_plus.rb +27 -14
- data/lib/active_job/arguments_plus/version.rb +1 -1
- metadata +1 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: faf18c2e832c03c9b94389f0b778f47dab382b67
|
4
|
+
data.tar.gz: '0486b471b37a4132d484c266879f69d33847f3a9'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 396b4bbd83eb683b6b06ca103a215d909578b9155d8534f910aa2f7a5669bc99299e73e43f04675027270b903f03823512c604279bbfe8ff0d74ed7832ccb661
|
7
|
+
data.tar.gz: a32d88774ca7fe6793b9732143f7bc51b69a7172f6861663fc307ad110b82f13be6b31687a41137e8e8b0ca147cd985ad26aa5cc1212c279e4ca3aadcfa55819
|
@@ -1,5 +1,11 @@
|
|
1
1
|
require 'logger'
|
2
|
-
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'ph_model'
|
5
|
+
rescue LoadError
|
6
|
+
# ignore
|
7
|
+
end
|
8
|
+
|
3
9
|
require 'active_job/arguments'
|
4
10
|
require_relative 'arguments_plus/version'
|
5
11
|
|
@@ -7,20 +13,27 @@ ActiveJob::Arguments # pre-load so we extend the module
|
|
7
13
|
|
8
14
|
module ActiveJob
|
9
15
|
module ArgumentsPlus
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
16
|
+
def self.type_keys
|
17
|
+
@type_keys ||= begin
|
18
|
+
add_if_defined = lambda { |tk, klass_name|
|
19
|
+
tk[klass_name.constantize] = "_aj_#{klass_name.underscore}" if const_defined?(klass_name)
|
20
|
+
}
|
21
|
+
tk = {}
|
22
|
+
add_if_defined.call(tk, 'Module')
|
23
|
+
add_if_defined.call(tk, 'Logger')
|
24
|
+
add_if_defined.call(tk, 'PhModel')
|
25
|
+
tk
|
26
|
+
end
|
27
|
+
end
|
15
28
|
|
16
29
|
def serialize_argument(argument)
|
17
|
-
arg_klass, info =
|
30
|
+
arg_klass, info = type_keys.find { |klass, _| klass === argument }
|
18
31
|
arg_klass ? send("serialize_#{class_to_method(arg_klass.name)}", argument) : super
|
19
32
|
end
|
20
33
|
|
21
34
|
def deserialize_argument(argument)
|
22
35
|
if argument.is_a?(Hash) && argument.size == 1
|
23
|
-
arg_klass, _ =
|
36
|
+
arg_klass, _ = type_keys.find { |_, key| argument.key?(key) }
|
24
37
|
arg_klass ? send("deserialize_#{class_to_method(arg_klass.name)}") : super
|
25
38
|
else
|
26
39
|
super
|
@@ -34,11 +47,11 @@ module ActiveJob
|
|
34
47
|
end
|
35
48
|
|
36
49
|
def key_for(klass)
|
37
|
-
case
|
50
|
+
case type_keys[klass]
|
38
51
|
when Hash
|
39
|
-
|
52
|
+
type_keys[klass][:key]
|
40
53
|
else
|
41
|
-
|
54
|
+
type_keys[klass]
|
42
55
|
end
|
43
56
|
end
|
44
57
|
|
@@ -61,7 +74,7 @@ module ActiveJob
|
|
61
74
|
|
62
75
|
def serialize_ph_model(argument)
|
63
76
|
{
|
64
|
-
key_for(
|
77
|
+
key_for(PhModel) => {
|
65
78
|
'type' => argument.class.name,
|
66
79
|
'data' => argument.as_json,
|
67
80
|
}
|
@@ -69,8 +82,8 @@ module ActiveJob
|
|
69
82
|
end
|
70
83
|
|
71
84
|
def deserialize_ph_model(argument)
|
72
|
-
info = argument[key_for(
|
73
|
-
info['type'].constantize.build
|
85
|
+
info = argument[key_for(PhModel)]
|
86
|
+
info['type'].constantize.send(:build, info['data'])
|
74
87
|
end
|
75
88
|
end
|
76
89
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_job-arguments_plus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Banasik
|
@@ -10,20 +10,6 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2017-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: ph_model
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.1'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.1'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: activejob
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|