evnt 3.0 → 3.0.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: ef2fa95d09eb421d9912263783747d85451a4d5e
4
- data.tar.gz: af36eef1ef9d3c940e68c2eb6ee0b35b3212964c
3
+ metadata.gz: 63694dd6640e60116fa220f26d2c5c534434f488
4
+ data.tar.gz: b8a2784a560444babd7ac31a9d43d4cf73b4be91
5
5
  SHA512:
6
- metadata.gz: d40c2f8c4e51b0d505911f3059da2b2f4d4ade398131f20c38797da2e1f4ad370858b9dcf3843521ae91529ed0331cdf4a47fd6a6b2137a3751a5cd486bb5d61
7
- data.tar.gz: ada5ce42640430d0f38c4773461be4edb5a012c64b20253e6a12a76cd3b0d5d47835100078e2645cfb2fd98d37c620e172cf44a53da1a3abdbddbffdea0d1728
6
+ metadata.gz: 4c1381e123afa1b6dfac53d92086102a5d57167d90dbfbaa5e72c59af1aff1bf71ccd48766d33841e265c8875db73812a582600eb192e2d35ea0cb324559c795
7
+ data.tar.gz: e1baebd245175ff2034607294c4e4836579d6f03148de64cbbc36b60211da29066dec7623263408799c5afbe1296d468f78c24628d614cf139a79ce2fb802252
data/README.md CHANGED
@@ -34,6 +34,7 @@ Commands are used to run single tasks on the system. It's like a controller on a
34
34
 
35
35
  Every command has three steps to execute:
36
36
 
37
+ - The params normalization which normalize the parameters used to run the command.
37
38
  - The params validation which validates the parameters used to run the command.
38
39
  - The logic validation which checks the command can be executed in compliance with the system rules.
39
40
  - The event intialization which initializes an event object used to save the command.
@@ -43,6 +44,10 @@ An example of command should be:
43
44
  ```ruby
44
45
  class CreateOrderCommand < Evnt::Command
45
46
 
47
+ to_normalize_params do
48
+ params[:quantity] = params[:quantity].to_i
49
+ end
50
+
46
51
  to_validate_params do
47
52
  # check params presence
48
53
  err 'User should be present' if params[:user_id].blank?
@@ -7,7 +7,7 @@ require 'evnt/handler'
7
7
  require 'evnt/validator'
8
8
 
9
9
  ##
10
- # Evnt is a gem developed to integrate a test driven development
10
+ # Evnt is a gem developed to integrate a event driven development
11
11
  # and CQRS pattern inside a ruby project.
12
12
  # Evnt is developed to be used over all kinds of projects and
13
13
  # frameworks (like Ruby on Rails or Sinatra), so it contains
@@ -26,8 +26,8 @@ module Evnt
26
26
  #
27
27
  # * +exceptions+ - Boolean value used to activate the throw of excetions.
28
28
  ##
29
- def initialize(params, _options: {})
30
- _init_command_data(params, _options)
29
+ def initialize(params)
30
+ _init_command_data(params)
31
31
  _run_command_steps
32
32
  end
33
33
 
@@ -105,14 +105,15 @@ module Evnt
105
105
  private
106
106
 
107
107
  # This function initializes the command required data.
108
- def _init_command_data(params, options)
108
+ def _init_command_data(params)
109
109
  # set state
110
110
  @state = {
111
111
  result: true,
112
112
  errors: []
113
113
  }
114
-
114
+
115
115
  # set options
116
+ options = params[:_options] || {}
116
117
  @options = {
117
118
  exceptions: options[:exceptions] || false
118
119
  }
@@ -124,6 +125,7 @@ module Evnt
124
125
  # This function calls requested steps (callback) for the command.
125
126
  def _run_command_steps
126
127
  _validate_single_params
128
+ _normalize_params if @state[:result] && defined?(_normalize_params)
127
129
  _validate_params if @state[:result] && defined?(_validate_params)
128
130
  _validate_logic if @state[:result] && defined?(_validate_logic)
129
131
  _initialize_events if @state[:result] && defined?(_initialize_events)
@@ -144,7 +146,7 @@ module Evnt
144
146
  end
145
147
  end
146
148
 
147
- @params.freeze
149
+ @params
148
150
  end
149
151
 
150
152
  # Class functions:
@@ -162,6 +164,11 @@ module Evnt
162
164
  instance_variable_set(:@_validations, validations)
163
165
  end
164
166
 
167
+ # This function sets the normalize params function for the command.
168
+ def to_normalize_params(&block)
169
+ define_method('_normalize_params', &block)
170
+ end
171
+
165
172
  # This function sets the validate params function for the command.
166
173
  def to_validate_params(&block)
167
174
  define_method('_validate_params', &block)
@@ -38,7 +38,13 @@ module Evnt
38
38
  #
39
39
  # ==== Attributes
40
40
  #
41
- # * +params+ - The list of parameters for the command.
41
+ # * +params+ - The list of parameters for the event.
42
+ # * +_options+ - The list of options for the event.
43
+ #
44
+ # ==== Options
45
+ #
46
+ # * +silent+ - Boolean value used to avoid the call of the notify method of
47
+ # handlers.
42
48
  ##
43
49
  def initialize(params)
44
50
  _init_event_data(params)
@@ -71,6 +77,12 @@ module Evnt
71
77
  reloaded: !params[:evnt].nil?
72
78
  }
73
79
 
80
+ # set options
81
+ options = params[:_options] || {}
82
+ @options = {
83
+ silent: options[:silent] || false
84
+ }
85
+
74
86
  # set payload
75
87
  payload = params.reject { |k, _v| k[0] == '_' }
76
88
  @payload = @state[:reloaded] ? payload : _generate_payload(payload)
@@ -113,6 +125,7 @@ module Evnt
113
125
  # This function notify all handlers for the event.
114
126
  def _notify_handlers
115
127
  return unless self.class._handlers
128
+ return if @options[:silent]
116
129
 
117
130
  # notify every handler
118
131
  self.class._handlers.each do |handler|
@@ -5,6 +5,6 @@ module Evnt
5
5
  ##
6
6
  # Constant containing the current gem version.
7
7
  ##
8
- VERSION = '3.0'
8
+ VERSION = '3.0.1'
9
9
 
10
10
  end
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.0'
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ideonetwork
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-17 00:00:00.000000000 Z
11
+ date: 2018-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler