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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b4453a702970a4c1eae1ef9eaa71186ae0ec440b
4
- data.tar.gz: d9e1dd31fe8e646b110cfe0488a112fc1b2bc836
3
+ metadata.gz: faf18c2e832c03c9b94389f0b778f47dab382b67
4
+ data.tar.gz: '0486b471b37a4132d484c266879f69d33847f3a9'
5
5
  SHA512:
6
- metadata.gz: 99cb9c9e3673c202046a1d023260b3645d885d3bc1ef77a6416e0a2f40bbe69cc41f899271abefb6f6a1f86d1c015a0c0ee6c4d47a841e95dcd1e123b437a993
7
- data.tar.gz: 578a208b4f59b0fd6a6a52ec8a7beb6b47fdd7fce0036ca8886220c0a9599dea24767ed17fbdbf66236f1f7b0577ee09ca941a73bb52fbc3093c9f5e720c3888
6
+ metadata.gz: 396b4bbd83eb683b6b06ca103a215d909578b9155d8534f910aa2f7a5669bc99299e73e43f04675027270b903f03823512c604279bbfe8ff0d74ed7832ccb661
7
+ data.tar.gz: a32d88774ca7fe6793b9732143f7bc51b69a7172f6861663fc307ad110b82f13be6b31687a41137e8e8b0ca147cd985ad26aa5cc1212c279e4ca3aadcfa55819
@@ -1,5 +1,11 @@
1
1
  require 'logger'
2
- require 'ph_model'
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
- TYPE_KEYS = {
11
- Module => '_aj_module',
12
- Logger => '_aj_logger',
13
- PhModel => '_aj_ph_model'
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 = TYPE_KEYS.find { |klass, _| klass === argument }
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, _ = TYPE_KEYS.find { |_, key| argument.key?(key) }
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 TYPE_KEYS[klass]
50
+ case type_keys[klass]
38
51
  when Hash
39
- TYPE_KEYS[klass][:key]
52
+ type_keys[klass][:key]
40
53
  else
41
- TYPE_KEYS[klass]
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(Logger) => {
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(Logger)]
73
- info['type'].constantize.build(info['data'])
85
+ info = argument[key_for(PhModel)]
86
+ info['type'].constantize.send(:build, info['data'])
74
87
  end
75
88
  end
76
89
 
@@ -1,5 +1,5 @@
1
1
  module ActiveJob
2
2
  module ArgumentsPlus
3
- VERSION = '0.1.0'
3
+ VERSION = '0.1.1'
4
4
  end
5
5
  end
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.0
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