evnt 3.4.0 → 3.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/evnt/event.rb +17 -4
- data/lib/evnt/handler.rb +5 -0
- data/lib/evnt/query.rb +9 -1
- data/lib/evnt/query_activerecord.rb +28 -3
- data/lib/evnt/version.rb +1 -1
- data/lib/generators/evnt/templates/initializer/app/events/application_event.rb +1 -1
- data/lib/generators/evnt/templates/initializer/app/queries/application_query.rb +1 -1
- data/lib/generators/evnt/templates/initializer/config/initializers/evnt.rb +5 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1147304064293c3dfa71574a83935a8328b98f91f9ece384d9bf32c8bc4195c2
|
4
|
+
data.tar.gz: 1b74795c01d50f1c00c3f45f6938a42493d5e9e5609c72b8df1a3bcce98e33d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f54bfe9c4b7ffeeea71df3a393e932ac2d51d9c0d96928f9ee35ec478c264dc3608f65bf16e10bc81e916290ef1a51cfcaade7481d2abe075a8791d43c7add7d
|
7
|
+
data.tar.gz: 8788243241cc12dc09edb4686d375bab113db99aa5bda599958f1c175153e1e72658757d8e1be1167781fb36e9a8c7a069ea333aa75d49d2c0704ea877690c13
|
data/lib/evnt/event.rb
CHANGED
@@ -213,6 +213,22 @@ module Evnt
|
|
213
213
|
define_method('_attributes', -> { return event_attributes })
|
214
214
|
end
|
215
215
|
|
216
|
+
# This function sets the write event function for the event.
|
217
|
+
def to_write_event(&block)
|
218
|
+
define_method('_write_event', &block)
|
219
|
+
end
|
220
|
+
|
221
|
+
# This function is used to add a new handler to the event from the external.
|
222
|
+
def add_handler(handler)
|
223
|
+
@handlers ||= []
|
224
|
+
@handlers.push(handler)
|
225
|
+
event_handlers = @handlers
|
226
|
+
|
227
|
+
define_method('_handlers', -> { return event_handlers })
|
228
|
+
end
|
229
|
+
|
230
|
+
# DEPRECATED
|
231
|
+
|
216
232
|
# This function sets the list of handlers for the event.
|
217
233
|
def handlers_are(handlers)
|
218
234
|
@handlers ||= []
|
@@ -220,11 +236,8 @@ module Evnt
|
|
220
236
|
event_handlers = @handlers
|
221
237
|
|
222
238
|
define_method('_handlers', -> { return event_handlers })
|
223
|
-
end
|
224
239
|
|
225
|
-
|
226
|
-
def to_write_event(&block)
|
227
|
-
define_method('_write_event', &block)
|
240
|
+
warn '[DEPRECATION] `handlers_are` is deprecated. Please use handler `listen` instead.'
|
228
241
|
end
|
229
242
|
|
230
243
|
end
|
data/lib/evnt/handler.rb
CHANGED
@@ -73,6 +73,11 @@ module Evnt
|
|
73
73
|
# This class contain the list of settings for the handler.
|
74
74
|
class << self
|
75
75
|
|
76
|
+
# This function permits handler to listen specific event.
|
77
|
+
def listen(event)
|
78
|
+
event.add_handler(new)
|
79
|
+
end
|
80
|
+
|
76
81
|
# This function sets the blocks executed for a specific event.
|
77
82
|
def on(event_name, &block)
|
78
83
|
@_current_event_name = event_name
|
data/lib/evnt/query.rb
CHANGED
@@ -16,10 +16,18 @@ module Evnt
|
|
16
16
|
raise SystemCallError, 'Query can not be initialized'
|
17
17
|
end
|
18
18
|
|
19
|
-
def self.as_json(
|
19
|
+
def self.as_json(_query, _parameters = {})
|
20
20
|
raise NotImplementedError, 'As json method should be implemented on Query subclasses'
|
21
21
|
end
|
22
22
|
|
23
|
+
def self.as_string(_query, _parameters = {})
|
24
|
+
raise NotImplementedError, 'As string method should be implemented on Query subclasses'
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.as_bytes(_query, _parameters = {})
|
28
|
+
raise NotImplementedError, 'As bytes method should be implemented on Query subclasses'
|
29
|
+
end
|
30
|
+
|
23
31
|
# Helpers:
|
24
32
|
############################################################################
|
25
33
|
|
@@ -17,10 +17,11 @@ module Evnt
|
|
17
17
|
#
|
18
18
|
# * +query+ - The name of the query that should be executed.
|
19
19
|
# * +parameters+ - An object containing the parameters for the query.
|
20
|
-
# * +except+ - The list of attributes that should be removed from the json.
|
21
|
-
# * +only+ - The list of parameters that shoud be accepted for the json.
|
22
20
|
##
|
23
|
-
def self.as_json(query, parameters
|
21
|
+
def self.as_json(query, parameters = {})
|
22
|
+
except = parameters[:_except] || []
|
23
|
+
only = parameters[:_only] || []
|
24
|
+
|
24
25
|
result = send(query, parameters).as_json
|
25
26
|
return result unless except.length.positive? || only.length.positive?
|
26
27
|
|
@@ -28,6 +29,30 @@ module Evnt
|
|
28
29
|
clean_unpermitted_attributes_from_json(result, result.keys - only) if only.length.positive?
|
29
30
|
end
|
30
31
|
|
32
|
+
##
|
33
|
+
# This function should run a query and return the result as a string object.
|
34
|
+
#
|
35
|
+
# ==== Attributes
|
36
|
+
#
|
37
|
+
# * +query+ - The name of the query that should be executed.
|
38
|
+
# * +parameters+ - An object containing the parameters for the query.
|
39
|
+
##
|
40
|
+
def self.as_string(query, parameters = {})
|
41
|
+
as_json(query, parameters).to_s
|
42
|
+
end
|
43
|
+
|
44
|
+
##
|
45
|
+
# This function should run a query and return the result as a bytes array.
|
46
|
+
#
|
47
|
+
# ==== Attributes
|
48
|
+
#
|
49
|
+
# * +query+ - The name of the query that should be executed.
|
50
|
+
# * +parameters+ - An object containing the parameters for the query.
|
51
|
+
##
|
52
|
+
def self.as_bytes(query, parameters = {})
|
53
|
+
as_string(query, parameters).bytes.to_a
|
54
|
+
end
|
55
|
+
|
31
56
|
end
|
32
57
|
|
33
58
|
end
|
data/lib/evnt/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: evnt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ideonetwork
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-04-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -81,6 +81,7 @@ files:
|
|
81
81
|
- lib/generators/evnt/templates/initializer/app/events/application_event.rb
|
82
82
|
- lib/generators/evnt/templates/initializer/app/handlers/application_handler.rb
|
83
83
|
- lib/generators/evnt/templates/initializer/app/queries/application_query.rb
|
84
|
+
- lib/generators/evnt/templates/initializer/config/initializers/evnt.rb
|
84
85
|
- lib/generators/evnt/templates/initializer/test/commands/application_command_test.rb
|
85
86
|
- lib/generators/evnt/templates/initializer/test/events/application_event_test.rb
|
86
87
|
- lib/generators/evnt/templates/initializer/test/handlers/application_handler_test.rb
|