evnt 3.3.0 → 3.4.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: 8ef1b5762fd449d75c4ae69dc161adcbb551d447c660e818e99b99a017fa31df
4
- data.tar.gz: 54abf9e98b18f38fa5c11b3dd04413f0acad251840b48d234452f1575128e504
3
+ metadata.gz: 2e6642f8281f70c2e1fa58135df7275bff548259ae713d451495e31d48ef2d06
4
+ data.tar.gz: 68ac7a94843664a0b6d7ad88136afb45bbea32530b8b2dce58908edd2ca93607
5
5
  SHA512:
6
- metadata.gz: d95dcf19b416dc055707153fae3ef77abd188e8291417f39966677677523084665db75842b4dc2ee592e583acb2d63955176027aa87e1ca7135b8658aef82437
7
- data.tar.gz: 3fd2d0dfc03ed1b5431358bfc52bf6eb125b6dfc067c8808f8e7ed2aa8bece0cb7f96ea58780cc916955ec306c7b42cea7e8d7b51fe426c5423f3713627c048e
6
+ metadata.gz: 90e84269ee4dce4cb75ab51253e4bd5e5e865484e2eb0d701561a18abeb26c73607eae13f9dd2043cdfc4e3dda186123ebb6c14edd6f7b3c5bae8db011c56135
7
+ data.tar.gz: 15d50a32bbea10cad774c418cbcdf96aaa84044ccdb4daaa41cdb11e58d2c47c68660d9b5d964183214bc65645ff6ac5a6afa0fd08e4d2b064311fe9654c9927
data/README.md CHANGED
@@ -5,11 +5,12 @@
5
5
 
6
6
  CQRS and Event Driven Development architecture for Ruby projects.
7
7
 
8
- Evnt is a Ruby gem used to design software following the CQRS and Event driven development pattern. The idea behind Evnt is to develop the business logic of the system using three different classes:
8
+ Evnt is a Ruby gem used to design software following the CQRS and Event driven development pattern. The idea behind Evnt is to develop the business logic of the system using four different classes:
9
9
 
10
10
  - **Commands**: actions executed by actors that can be completed or stopped by the system.
11
11
  - **Events**: something that it's already happen and should be logged somewhere.
12
- - **Handlers**: event listeners that perform specific tasks.
12
+ - **Handlers**: event listeners that perform specific tasks.
13
+ - **Queries**: list of queries used to read data from database.
13
14
 
14
15
  The full documentation of these classes can be found here: https://ideonetwork.github.io/evnt
15
16
 
data/lib/evnt.rb CHANGED
@@ -6,6 +6,9 @@ require 'evnt/event'
6
6
  require 'evnt/handler'
7
7
  require 'evnt/validator'
8
8
 
9
+ require 'evnt/query'
10
+ require 'evnt/query_activerecord'
11
+
9
12
  ##
10
13
  # Evnt is a gem developed to integrate a event driven development
11
14
  # and CQRS pattern inside a ruby project.
data/lib/evnt/query.rb ADDED
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Evnt
4
+
5
+ ##
6
+ # Queries are used to read and prepare data from the database
7
+ # to the client.
8
+ # The Query class should contain only helpers used to develop custom queries.
9
+ ##
10
+ class Query
11
+
12
+ ##
13
+ # The constructor should not be used. Use class method insthead.
14
+ ##
15
+ def initialize
16
+ raise SystemCallError, 'Query can not be initialized'
17
+ end
18
+
19
+ def self.as_json(query, parameters, except: [], only: [])
20
+ raise NotImplementedError, 'As json method should be implemented on Query subclasses'
21
+ end
22
+
23
+ # Helpers:
24
+ ############################################################################
25
+
26
+ def self.clean_unpermitted_attributes_from_json(obj, unpermitted_attributes)
27
+ if obj.is_a?(Array)
28
+ obj.map { |o| unpermitted_attributes.each { |attribute| o.delete(attribute.to_s) } }
29
+ else
30
+ unpermitted_attributes.each { |attribute| obj.delete(attribute.to_s) }
31
+ end
32
+
33
+ obj
34
+ end
35
+
36
+ private_class_method :clean_unpermitted_attributes_from_json
37
+
38
+ end
39
+
40
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Evnt
4
+
5
+ ##
6
+ # Queries are used to read and prepare data from the database
7
+ # to the client.
8
+ # The QueryActivercord class shuld contain helpers used to develop custom
9
+ # queries based on activerecord.
10
+ ##
11
+ class QueryActiverecord < Evnt::Query
12
+
13
+ ##
14
+ # This function should run a query and return the result as a hash/json object.
15
+ #
16
+ # ==== Attributes
17
+ #
18
+ # * +query+ - The name of the query that should be executed.
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
+ ##
23
+ def self.as_json(query, parameters, except: [], only: [])
24
+ result = send(query, parameters).as_json
25
+ return result unless except.length.positive? || only.length.positive?
26
+
27
+ clean_unpermitted_attributes_from_json(result, except) if except.length.positive?
28
+ clean_unpermitted_attributes_from_json(result, result.keys - only) if only.length.positive?
29
+ end
30
+
31
+ end
32
+
33
+ end
data/lib/evnt/version.rb CHANGED
@@ -3,6 +3,6 @@
3
3
  # Evnt.
4
4
  module Evnt
5
5
 
6
- VERSION = '3.3.0'
6
+ VERSION = '3.4.0'
7
7
 
8
8
  end
@@ -23,6 +23,7 @@ module Evnt
23
23
  application "config.autoload_paths += %W[\#{Rails.root}/app/commands]"
24
24
  application "config.autoload_paths += %W[\#{Rails.root}/app/events]"
25
25
  application "config.autoload_paths += %W[\#{Rails.root}/app/handlers]"
26
+ application "config.autoload_paths += %W[\#{Rails.root}/app/queries]"
26
27
  end
27
28
 
28
29
  def manage_migrated_option
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/generators/base'
4
+
5
+ module Evnt
6
+
7
+ # QueryGenerator.
8
+ class QueryGenerator < Rails::Generators::Base
9
+
10
+ source_root File.expand_path('../templates', __FILE__)
11
+
12
+ argument :informations, type: :array, optional: false
13
+
14
+ def create_comand
15
+ path = informations.first.split('::')
16
+ @query_class = path.last.camelize
17
+ @query_modules = path - [path.last]
18
+ @query_params = informations - [informations.first]
19
+
20
+ template(
21
+ './query/query.rb.erb',
22
+ query_path
23
+ )
24
+ end
25
+
26
+ def query_path
27
+ path = './app/queries'
28
+ @query_modules.map { |m| path = "#{path}/#{m.underscore}" }
29
+ path = "#{path}/#{@query_class.underscore}.rb"
30
+ path
31
+ end
32
+
33
+ end
34
+
35
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ # ApplicationQuery.
4
+ class ApplicationQuery < Evnt::QueryActiveRecord
5
+
6
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+ <% @query_modules.each_with_index do |module_name, index| %>
3
+ <%= ' ' * index %>module <%= module_name %>
4
+ <% end %>
5
+ <%= ' ' * @query_modules.length %># <%= @query_class %>
6
+ <%= ' ' * @query_modules.length %>class <%= @query_class %> < ApplicationQuery
7
+ <% @query_params.each do |param| %>
8
+ <%= ' ' * (@query_modules.length + 1) %>def self.<%= param %>; end
9
+ <% end %>
10
+ <%= ' ' * @query_modules.length %>end
11
+ <% @query_modules.each_with_index do |_module_name, index| %>
12
+ <%= ' ' * (@query_modules.length - index - 1) %>end
13
+ <% 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.3.0
4
+ version: 3.4.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-13 00:00:00.000000000 Z
11
+ date: 2018-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -65,21 +65,26 @@ files:
65
65
  - lib/evnt/command.rb
66
66
  - lib/evnt/event.rb
67
67
  - lib/evnt/handler.rb
68
+ - lib/evnt/query.rb
69
+ - lib/evnt/query_activerecord.rb
68
70
  - lib/evnt/validator.rb
69
71
  - lib/evnt/version.rb
70
72
  - lib/generators/evnt/command_generator.rb
71
73
  - lib/generators/evnt/event_generator.rb
72
74
  - lib/generators/evnt/handler_generator.rb
73
75
  - lib/generators/evnt/initializer_generator.rb
76
+ - lib/generators/evnt/query_generator.rb
74
77
  - lib/generators/evnt/templates/command/command.rb.erb
75
78
  - lib/generators/evnt/templates/event/event.rb.erb
76
79
  - lib/generators/evnt/templates/handler/handler.rb.erb
77
80
  - lib/generators/evnt/templates/initializer/app/commands/application_command.rb
78
81
  - lib/generators/evnt/templates/initializer/app/events/application_event.rb
79
82
  - lib/generators/evnt/templates/initializer/app/handlers/application_handler.rb
83
+ - lib/generators/evnt/templates/initializer/app/queries/application_query.rb
80
84
  - lib/generators/evnt/templates/initializer/test/commands/application_command_test.rb
81
85
  - lib/generators/evnt/templates/initializer/test/events/application_event_test.rb
82
86
  - lib/generators/evnt/templates/initializer/test/handlers/application_handler_test.rb
87
+ - lib/generators/evnt/templates/query/query.rb.erb
83
88
  homepage: http://ideonetwork.it/
84
89
  licenses:
85
90
  - MIT