active_job-arguments_plus 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b4453a702970a4c1eae1ef9eaa71186ae0ec440b
4
+ data.tar.gz: d9e1dd31fe8e646b110cfe0488a112fc1b2bc836
5
+ SHA512:
6
+ metadata.gz: 99cb9c9e3673c202046a1d023260b3645d885d3bc1ef77a6416e0a2f40bbe69cc41f899271abefb6f6a1f86d1c015a0c0ee6c4d47a841e95dcd1e123b437a993
7
+ data.tar.gz: 578a208b4f59b0fd6a6a52ec8a7beb6b47fdd7fce0036ca8886220c0a9599dea24767ed17fbdbf66236f1f7b0577ee09ca941a73bb52fbc3093c9f5e720c3888
@@ -0,0 +1,80 @@
1
+ require 'logger'
2
+ require 'ph_model'
3
+ require 'active_job/arguments'
4
+ require_relative 'arguments_plus/version'
5
+
6
+ ActiveJob::Arguments # pre-load so we extend the module
7
+
8
+ module ActiveJob
9
+ module ArgumentsPlus
10
+ TYPE_KEYS = {
11
+ Module => '_aj_module',
12
+ Logger => '_aj_logger',
13
+ PhModel => '_aj_ph_model'
14
+ }
15
+
16
+ def serialize_argument(argument)
17
+ arg_klass, info = TYPE_KEYS.find { |klass, _| klass === argument }
18
+ arg_klass ? send("serialize_#{class_to_method(arg_klass.name)}", argument) : super
19
+ end
20
+
21
+ def deserialize_argument(argument)
22
+ if argument.is_a?(Hash) && argument.size == 1
23
+ arg_klass, _ = TYPE_KEYS.find { |_, key| argument.key?(key) }
24
+ arg_klass ? send("deserialize_#{class_to_method(arg_klass.name)}") : super
25
+ else
26
+ super
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def class_to_method(klass_name)
33
+ klass_name.underscore
34
+ end
35
+
36
+ def key_for(klass)
37
+ case TYPE_KEYS[klass]
38
+ when Hash
39
+ TYPE_KEYS[klass][:key]
40
+ else
41
+ TYPE_KEYS[klass]
42
+ end
43
+ end
44
+
45
+ def serialize_logger(_)
46
+ { key_for(Logger) => true }
47
+ end
48
+
49
+ def deserialize_logger(_)
50
+ # Yes this is kinda lame, but loggers can't really be serialized ...
51
+ Logger.new(STDOUT)
52
+ end
53
+
54
+ def serialize_module(argument)
55
+ { key_for(Logger) => argument.name }
56
+ end
57
+
58
+ def deserialize_module(argument)
59
+ argument[key_for(Logger)].constantize
60
+ end
61
+
62
+ def serialize_ph_model(argument)
63
+ {
64
+ key_for(Logger) => {
65
+ 'type' => argument.class.name,
66
+ 'data' => argument.as_json,
67
+ }
68
+ }
69
+ end
70
+
71
+ def deserialize_ph_model(argument)
72
+ info = argument[key_for(Logger)]
73
+ info['type'].constantize.build(info['data'])
74
+ end
75
+ end
76
+
77
+ module Arguments
78
+ extend ArgumentsPlus
79
+ end
80
+ end
@@ -0,0 +1,5 @@
1
+ module ActiveJob
2
+ module ArgumentsPlus
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_job-arguments_plus
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Piotr Banasik
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-11-28 00:00:00.000000000 Z
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
+ - !ruby/object:Gem::Dependency
28
+ name: activejob
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '12.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '12.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.16'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.16'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubygems-tasks
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.2'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.2'
83
+ description: "."
84
+ email: piotr.banasik@gmail.com
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - lib/active_job/arguments_plus.rb
90
+ - lib/active_job/arguments_plus/version.rb
91
+ homepage: https://github.com/imrealtor/active_job-arguments_plus
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2.2'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.6.13
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: ActiveJob Argument Serialization Extension
115
+ test_files: []