active_job-arguments_plus 0.1.2 → 0.2.0
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 +5 -5
- data/lib/active_job/arguments_plus.rb +40 -15
- data/lib/active_job/arguments_plus/version.rb +1 -1
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 31db58fabeb5463eee87082fcc2d37054e442f902aff17347d01806ef57f06b2
|
4
|
+
data.tar.gz: 57ca467cba0f7973f0d381351c6298a03b6714698ed3fe39e1dda9d6ec44c78d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28359af628b4dd7df6a777f45a5e31435b23c607715ddacc8759dff7f69e5df2fae6ab09c33b1a4a4699190551f7492aade83d35a7d913d4707ca7edbf67f3a5
|
7
|
+
data.tar.gz: 75eb938bb765324d2894e3ea3754c360249ab493ef5e2108f50b789c3bf258628161987a5d751e4efd95a74630e800b825cb1337ebbe1640bb8793c4ead1ba57
|
@@ -7,6 +7,7 @@ rescue LoadError
|
|
7
7
|
end
|
8
8
|
|
9
9
|
require 'active_job/arguments'
|
10
|
+
require 'globalid'
|
10
11
|
require_relative 'arguments_plus/version'
|
11
12
|
|
12
13
|
ActiveJob::Arguments # pre-load so we extend the module
|
@@ -22,19 +23,20 @@ module ActiveJob
|
|
22
23
|
add_if_defined.call(tk, 'Module')
|
23
24
|
add_if_defined.call(tk, 'Logger')
|
24
25
|
add_if_defined.call(tk, 'PhModel')
|
26
|
+
add_if_defined.call(tk, 'Time')
|
25
27
|
tk
|
26
28
|
end
|
27
29
|
end
|
28
30
|
|
29
31
|
def serialize_argument(argument)
|
30
|
-
arg_klass,
|
31
|
-
arg_klass ?
|
32
|
+
arg_klass, _ = type_keys.find { |klass, _| klass === argument }
|
33
|
+
arg_klass ? serialize_local_argument(arg_klass, argument) : super
|
32
34
|
end
|
33
35
|
|
34
36
|
def deserialize_argument(argument)
|
35
37
|
if argument.is_a?(Hash) && argument.size == 1
|
36
38
|
arg_klass, _ = type_keys.find { |_, key| argument.key?(key) }
|
37
|
-
arg_klass ?
|
39
|
+
arg_klass ? deserialize_local_argument(arg_klass, argument) : super
|
38
40
|
else
|
39
41
|
super
|
40
42
|
end
|
@@ -42,6 +44,16 @@ module ActiveJob
|
|
42
44
|
|
43
45
|
private
|
44
46
|
|
47
|
+
def serialize_local_argument(arg_klass, argument)
|
48
|
+
value = send("serialize_#{class_to_method(arg_klass.name)}", argument)
|
49
|
+
serialize_generic(arg_klass, value)
|
50
|
+
end
|
51
|
+
|
52
|
+
def deserialize_local_argument(arg_klass, argument)
|
53
|
+
value = deserialize_generic(arg_klass, argument)
|
54
|
+
send("deserialize_#{class_to_method(arg_klass.name)}", value)
|
55
|
+
end
|
56
|
+
|
45
57
|
delegate :type_keys, to: 'ActiveJob::ArgumentsPlus'
|
46
58
|
|
47
59
|
def class_to_method(klass_name)
|
@@ -57,8 +69,16 @@ module ActiveJob
|
|
57
69
|
end
|
58
70
|
end
|
59
71
|
|
72
|
+
def serialize_generic(klass, value)
|
73
|
+
{key_for(klass) => value}
|
74
|
+
end
|
75
|
+
|
76
|
+
def deserialize_generic(klass, argument)
|
77
|
+
argument[key_for(klass)]
|
78
|
+
end
|
79
|
+
|
60
80
|
def serialize_logger(_)
|
61
|
-
|
81
|
+
true
|
62
82
|
end
|
63
83
|
|
64
84
|
def deserialize_logger(_)
|
@@ -66,27 +86,32 @@ module ActiveJob
|
|
66
86
|
Logger.new(STDOUT)
|
67
87
|
end
|
68
88
|
|
69
|
-
def serialize_module(
|
70
|
-
|
89
|
+
def serialize_module(klass)
|
90
|
+
klass.name
|
71
91
|
end
|
72
92
|
|
73
|
-
def deserialize_module(
|
74
|
-
|
93
|
+
def deserialize_module(klass_name)
|
94
|
+
klass_name.constantize
|
75
95
|
end
|
76
96
|
|
77
|
-
def serialize_ph_model(
|
97
|
+
def serialize_ph_model(model)
|
78
98
|
{
|
79
|
-
|
80
|
-
|
81
|
-
'data' => argument.as_json,
|
82
|
-
}
|
99
|
+
'type' => model.class.name,
|
100
|
+
'data' => model.as_json,
|
83
101
|
}
|
84
102
|
end
|
85
103
|
|
86
|
-
def deserialize_ph_model(
|
87
|
-
info = argument[key_for(PhModel)]
|
104
|
+
def deserialize_ph_model(info)
|
88
105
|
info['type'].constantize.send(:build, info['data'])
|
89
106
|
end
|
107
|
+
|
108
|
+
def serialize_time(time)
|
109
|
+
time.to_f
|
110
|
+
end
|
111
|
+
|
112
|
+
def deserialize_time(unixtime)
|
113
|
+
Time.at(unixtime)
|
114
|
+
end
|
90
115
|
end
|
91
116
|
|
92
117
|
module Arguments
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_job-arguments_plus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Banasik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-02-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activejob
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '1.1'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
description: "."
|
98
112
|
email: piotr.banasik@gmail.com
|
99
113
|
executables: []
|
@@ -122,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
136
|
version: '0'
|
123
137
|
requirements: []
|
124
138
|
rubyforge_project:
|
125
|
-
rubygems_version: 2.
|
139
|
+
rubygems_version: 2.7.3
|
126
140
|
signing_key:
|
127
141
|
specification_version: 4
|
128
142
|
summary: ActiveJob Argument Serialization Extension
|