web-connect 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/netfira/web_connect/events.rb +1 -1
- data/lib/netfira/web_connect/model/record.rb +2 -0
- data/lib/netfira/web_connect/model/record/events.rb +63 -32
- data/lib/netfira/web_connect/model/record/file_record.rb +9 -0
- data/lib/netfira/web_connect/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a78c316aa0dd58c987d6a68648bdf9d2af9f851
|
4
|
+
data.tar.gz: 41e0fb236184473185bbd711308fe1a87ed9810d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6eab39887c6b60a94689193dc3d0cb167f7e32c37d76eee2b1803b013db5819413c643b26d3bf25b6d0762f4ae83c9baae5b1c61399597cb2548fa943fa36b3e
|
7
|
+
data.tar.gz: 696ab4061e29e06d5c394c087476a3e20540c00e5b66c84a20123990771f4a2c3119be3780d58bc391d76d4b02e3af137acdaeec7f36a4a15449e63de13753f1
|
@@ -7,7 +7,7 @@ module Netfira::WebConnect
|
|
7
7
|
def self.dispatch_event(timing, event, *args)
|
8
8
|
|
9
9
|
# Allow multiple timings to be dispatched simultaneously, e.g. [:on, :after]
|
10
|
-
return timing.each{ |t| dispatch_event
|
10
|
+
return timing.each{ |t| dispatch_event(t, event, *args) { yield } } if timing.respond_to? :each
|
11
11
|
|
12
12
|
# The method to invoke, e.g. :on_update_product
|
13
13
|
target = :"#{timing}_#{event}"
|
@@ -4,49 +4,80 @@ module Netfira::WebConnect
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
6
|
included do
|
7
|
-
|
8
|
-
|
7
|
+
before_save :dispatch_before_update
|
8
|
+
around_save :dispatch_around_update
|
9
|
+
after_save :dispatch_after_update
|
10
|
+
before_destroy :dispatch_before_destroy
|
11
|
+
around_destroy :dispatch_around_destroy
|
12
|
+
after_destroy :dispatch_after_destroy
|
9
13
|
end
|
10
14
|
|
11
15
|
private
|
12
16
|
|
13
|
-
def
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
27
|
-
as_readonly do
|
28
|
-
dispatch_event :before, *named_event_args
|
29
|
-
dispatch_event :before, *event_args
|
30
|
-
dispatch_event :around, *named_event_args do
|
31
|
-
dispatch_event(:around, *event_args) { as_readwrite { yield } }
|
17
|
+
def update_event_args
|
18
|
+
@event_args ||= [].tap do |args|
|
19
|
+
previous = persisted? && changed_attributes.map do |key, value|
|
20
|
+
# TODO: solve this type casting issue without guessing by attribute names!
|
21
|
+
value = Checksum.new(value) if value and (key == 'checksum' or key == 'digest')
|
22
|
+
[key, value]
|
23
|
+
end.to_h
|
24
|
+
event_name = previous ? 'update' : 'create'
|
25
|
+
args << ["#{event_name}_#{self.class.single_name}", self]
|
26
|
+
args << [event_name, self]
|
27
|
+
if previous
|
28
|
+
previous.merge! previous_translations if has_languages?
|
29
|
+
args.each { |v| v << previous }
|
32
30
|
end
|
33
|
-
dispatch_event [:on, :after], *named_event_args
|
34
|
-
dispatch_event [:on, :after], *event_args
|
35
31
|
end
|
36
32
|
end
|
37
33
|
|
38
|
-
def
|
39
|
-
event_args
|
40
|
-
|
34
|
+
def destroy_event_args
|
35
|
+
@event_args ||= [
|
36
|
+
["delete_#{self.class.single_name}", self],
|
37
|
+
['delete', self]
|
38
|
+
]
|
39
|
+
end
|
40
|
+
|
41
|
+
def dispatch_with_args(args, *timing)
|
41
42
|
as_readonly do
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
if block_given?
|
44
|
+
dispatch_event timing, *args.first do
|
45
|
+
dispatch_event(timing, *args.last) { as_readwrite { yield } }
|
46
|
+
end
|
47
|
+
else
|
48
|
+
args.each { |x| dispatch_event timing, *x }
|
46
49
|
end
|
47
|
-
dispatch_event :after, *named_event_args
|
48
|
-
dispatch_event :after, *event_args
|
49
50
|
end
|
51
|
+
@event_args = nil if timing.include? :after
|
52
|
+
true
|
53
|
+
end
|
54
|
+
|
55
|
+
def dispatch_before_update
|
56
|
+
dispatch_with_args update_event_args, :before
|
57
|
+
end
|
58
|
+
|
59
|
+
def dispatch_around_update
|
60
|
+
dispatch_with_args(update_event_args, :around) { yield }
|
61
|
+
end
|
62
|
+
|
63
|
+
def dispatch_after_update
|
64
|
+
# Paperclip sets this up for us, but it runs after this handler, which
|
65
|
+
# means delegates don't get a saved image. Boo. We can save it twice,
|
66
|
+
# because the second save (the one Paperclip set up) will no-op.
|
67
|
+
attachment.save if has_file?
|
68
|
+
dispatch_with_args update_event_args, :on, :after
|
69
|
+
end
|
70
|
+
|
71
|
+
def dispatch_before_destroy
|
72
|
+
dispatch_with_args destroy_event_args, :before, :on
|
73
|
+
end
|
74
|
+
|
75
|
+
def dispatch_around_destroy
|
76
|
+
dispatch_with_args(destroy_event_args, :around) { yield }
|
77
|
+
end
|
78
|
+
|
79
|
+
def dispatch_after_destroy
|
80
|
+
dispatch_with_args destroy_event_args, :after
|
50
81
|
end
|
51
82
|
|
52
83
|
end
|
@@ -89,6 +89,15 @@ module Netfira::WebConnect
|
|
89
89
|
self.size = value
|
90
90
|
end
|
91
91
|
|
92
|
+
def url
|
93
|
+
exists? && remote_location || attachment.url
|
94
|
+
end
|
95
|
+
|
96
|
+
def exists?
|
97
|
+
!!(remote_location || attachment.exists?)
|
98
|
+
end
|
99
|
+
alias_method :exist?, :exists?
|
100
|
+
|
92
101
|
private
|
93
102
|
|
94
103
|
def set_file_defaults
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: web-connect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Neil E. Pearson
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-08-
|
12
|
+
date: 2014-08-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|