active_job-arguments_plus 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 56c423843a34137cf4a0097db95cf5af56e9f4af
4
- data.tar.gz: 54a9c43a542709b4157236df9e93747b41112ee5
2
+ SHA256:
3
+ metadata.gz: 31db58fabeb5463eee87082fcc2d37054e442f902aff17347d01806ef57f06b2
4
+ data.tar.gz: 57ca467cba0f7973f0d381351c6298a03b6714698ed3fe39e1dda9d6ec44c78d
5
5
  SHA512:
6
- metadata.gz: 6c0dfa8b07f4e590a49bc80ef5ea53c9dd0c79d51c6753dc039e64899a9696f5ee76a3683500fa5291f0a2157f624c8bb0014ea09876e86486da59027eb65d4d
7
- data.tar.gz: 363fcbe36d244fb2b162f9d9250d1ad52aa1d367ac084dc45a20d671413932b2fa59777d5ca95942770155d42531a89f1ea768e1acebe22e4b87b2ccc6628a64
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, info = type_keys.find { |klass, _| klass === argument }
31
- arg_klass ? send("serialize_#{class_to_method(arg_klass.name)}", argument) : super
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 ? send("deserialize_#{class_to_method(arg_klass.name)}", argument) : super
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
- { key_for(Logger) => true }
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(argument)
70
- { key_for(Module) => argument.name }
89
+ def serialize_module(klass)
90
+ klass.name
71
91
  end
72
92
 
73
- def deserialize_module(argument)
74
- argument[key_for(Module)].constantize
93
+ def deserialize_module(klass_name)
94
+ klass_name.constantize
75
95
  end
76
96
 
77
- def serialize_ph_model(argument)
97
+ def serialize_ph_model(model)
78
98
  {
79
- key_for(PhModel) => {
80
- 'type' => argument.class.name,
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(argument)
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
@@ -1,5 +1,5 @@
1
1
  module ActiveJob
2
2
  module ArgumentsPlus
3
- VERSION = '0.1.2'
3
+ VERSION = '0.2.0'
4
4
  end
5
5
  end
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.1.2
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: 2017-11-28 00:00:00.000000000 Z
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.6.13
139
+ rubygems_version: 2.7.3
126
140
  signing_key:
127
141
  specification_version: 4
128
142
  summary: ActiveJob Argument Serialization Extension