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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e6642f8281f70c2e1fa58135df7275bff548259ae713d451495e31d48ef2d06
4
- data.tar.gz: 68ac7a94843664a0b6d7ad88136afb45bbea32530b8b2dce58908edd2ca93607
3
+ metadata.gz: 1147304064293c3dfa71574a83935a8328b98f91f9ece384d9bf32c8bc4195c2
4
+ data.tar.gz: 1b74795c01d50f1c00c3f45f6938a42493d5e9e5609c72b8df1a3bcce98e33d8
5
5
  SHA512:
6
- metadata.gz: 90e84269ee4dce4cb75ab51253e4bd5e5e865484e2eb0d701561a18abeb26c73607eae13f9dd2043cdfc4e3dda186123ebb6c14edd6f7b3c5bae8db011c56135
7
- data.tar.gz: 15d50a32bbea10cad774c418cbcdf96aaa84044ccdb4daaa41cdb11e58d2c47c68660d9b5d964183214bc65645ff6ac5a6afa0fd08e4d2b064311fe9654c9927
6
+ metadata.gz: f54bfe9c4b7ffeeea71df3a393e932ac2d51d9c0d96928f9ee35ec478c264dc3608f65bf16e10bc81e916290ef1a51cfcaade7481d2abe075a8791d43c7add7d
7
+ data.tar.gz: 8788243241cc12dc09edb4686d375bab113db99aa5bda599958f1c175153e1e72658757d8e1be1167781fb36e9a8c7a069ea333aa75d49d2c0704ea877690c13
@@ -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
- # This function sets the write event function for the event.
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
@@ -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
@@ -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(query, parameters, except: [], only: [])
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, except: [], only: [])
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
@@ -3,6 +3,6 @@
3
3
  # Evnt.
4
4
  module Evnt
5
5
 
6
- VERSION = '3.4.0'
6
+ VERSION = '3.5.0'
7
7
 
8
8
  end
@@ -10,7 +10,7 @@ class ApplicationEvent < Evnt::Event
10
10
  EvntEvent.create(
11
11
  name: name,
12
12
  payload: payload
13
- )
13
+ ) || set_not_saved
14
14
  end
15
15
 
16
16
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # ApplicationQuery.
4
- class ApplicationQuery < Evnt::QueryActiveRecord
4
+ class ApplicationQuery < Evnt::QueryActiverecord
5
5
 
6
6
  end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Add here handler listeners.
4
+
5
+ # MyHandler.listen(MyEvent)
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.0
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-03-17 00:00:00.000000000 Z
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