nexus_domain_events 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 681696a0e3df1cbcbf54e5b0c1a103893a3cc75bc12bcd402c84eeee2176c7d7
4
+ data.tar.gz: 52ea658a2ea2d82d04661009c11592bb06e5ec11fc5732e9c0478c1c57883544
5
+ SHA512:
6
+ metadata.gz: b12d6d112682b360015a7c207d36e34372b001b5044820b73f4435c0a78cffc8e4dbd8920e96de13072fdb20058042b5c7a03ae083ef91f4e22aaf88696c56d8
7
+ data.tar.gz: 4d69e591d7dcb24ae53518dd735efa3689853fd9d77577f81e971923fe041fcd08ef34c97551ec69e6699d758c2f89603bebda6761f7c0a9a1052d58225a7037
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /.gem
10
+ /spec/lib/tmp
11
+ *.gem
12
+ Gemfile.lock
@@ -0,0 +1,36 @@
1
+ image: "ruby:2.7"
2
+
3
+ stages:
4
+ - release
5
+ - test
6
+
7
+ before_script:
8
+ - gem install bundler --no-document
9
+ - bundle install --jobs $(nproc) "${FLAGS[@]}"
10
+
11
+ rspec:
12
+ script:
13
+ - bundle exec rspec
14
+
15
+ rubocop:
16
+ script:
17
+ - bundle exec rubocop
18
+
19
+ release:
20
+ stage: release
21
+ rules:
22
+ - if: '$CI_COMMIT_TAG'
23
+ script:
24
+ - mkdir -p ~/.gem
25
+ - cp /builds/pub/nexus_domain_events.tmp/RUBYGEMS_CREDENTIALS ~/.gem/credentials
26
+ - chmod 0600 ~/.gem/credentials
27
+ - gem update --system
28
+ - ruby --version
29
+ - gem env version
30
+ - sed -i "s/0.0.0/$CI_COMMIT_TAG/g" lib/nexus_domain_events/version.rb
31
+ - gem build nexus_domain_events.gemspec
32
+ - gem push nexus_domain_events*.gem
33
+ artifacts:
34
+ paths:
35
+ - nexus_domain_events*.gem
36
+ expire_in: 30 days
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
@@ -0,0 +1,5 @@
1
+ inherit_gem:
2
+ rubocop-shopify: rubocop.yml
3
+
4
+ Style/GlobalVars:
5
+ Enabled: false
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+ source 'https://rubygems.org'
3
+
4
+ gemspec
5
+
6
+ gem 'rubocop'
7
+ gem 'rubocop-shopify', "~> 1.0.4", require: false
8
+
9
+ gem 'rspec'
@@ -0,0 +1,34 @@
1
+ # nexus_domain_events
2
+
3
+ Ruby based domain eventing tools
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'nexus_domain_events'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install nexus_domain_events
20
+
21
+ ## Usage
22
+
23
+ ## Development
24
+
25
+ To contribute to this gem, simple clone the repository, run `bundle install` and run tests:
26
+
27
+ ```shell script
28
+ bundle exec rspec
29
+ bundle exec rubocop
30
+ ```
31
+
32
+ ## Releasing
33
+
34
+ The release process is tied to the git tags. Simply creating a new tag and pushing will trigger a new release to rubygems.
@@ -0,0 +1,2 @@
1
+ # frozen_string_literal: true
2
+ require 'nexus_domain_events/event'
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'active_support'
5
+ require 'active_support/core_ext/time/calculations'
6
+
7
+ module NexusDomainEvents
8
+ # A domain event value object
9
+ class Event
10
+ attr_reader :message_name
11
+ attr_reader :actor
12
+ attr_reader :payload
13
+ attr_reader :message_id
14
+ attr_reader :created_at
15
+
16
+ def initialize(
17
+ message_name:,
18
+ actor:,
19
+ payload:,
20
+ message_id: nil,
21
+ created_at: nil
22
+ )
23
+ @message_name = message_name
24
+ @actor = actor
25
+ @payload = payload
26
+ @message_id = message_id || SecureRandom.uuid
27
+ @created_at = created_at || Time.now
28
+
29
+ errors = validate
30
+ raise StandardError.new(message: errors.join(', ')) unless errors.empty?
31
+ end
32
+
33
+ def validate
34
+ errors = []
35
+ errors << 'message_name cannot be blank' if @message_name.empty?
36
+ errors << 'actor must be an Int' unless @actor.is_a?(Integer)
37
+ errors << 'payload must be a Hash' unless @payload.is_a?(Hash)
38
+ errors << 'message_id cannot be blank' if @message_id.empty?
39
+ errors << 'created_at must be a Time' unless @created_at.is_a?(Time)
40
+ errors
41
+ end
42
+
43
+ def self.from_json(json)
44
+ parsed = JSON.parse(json, symbolize_names: true)
45
+ new(
46
+ message_name: parsed[:message_name],
47
+ actor: parsed[:actor],
48
+ payload: parsed[:payload],
49
+ message_id: parsed[:message_id],
50
+ created_at: Time.rfc3339(parsed[:created_at])
51
+ )
52
+ end
53
+
54
+ def to_json(*_args)
55
+ JSON.generate({
56
+ message_name: @message_name,
57
+ actor: @actor,
58
+ payload: @payload,
59
+ message_id: @message_id,
60
+ created_at: @created_at.rfc3339(9),
61
+ })
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+ module NexusDomainEvents
3
+ VERSION = '0.0.0'
4
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+ require_relative 'lib/nexus_domain_events/version'
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = 'nexus_domain_events'
6
+ spec.version = NexusDomainEvents::VERSION
7
+ spec.authors = ['Chris Harrison']
8
+ spec.email = ['chris.harrison@nexusmods.com']
9
+
10
+ spec.summary = 'Ruby based domain eventing tools'
11
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
12
+
13
+ # Specify which files should be added to the gem when it is released.
14
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
15
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
16
+ %x(git ls-files -z).split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ end
18
+ spec.require_paths = ['lib']
19
+ spec.add_dependency('activesupport')
20
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nexus_domain_events
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Chris Harrison
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-01-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description:
28
+ email:
29
+ - chris.harrison@nexusmods.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - ".gitlab-ci.yml"
36
+ - ".rspec"
37
+ - ".rubocop.yml"
38
+ - Gemfile
39
+ - README.md
40
+ - lib/nexus_domain_events.rb
41
+ - lib/nexus_domain_events/event.rb
42
+ - lib/nexus_domain_events/version.rb
43
+ - nexus_domain_events.gemspec
44
+ homepage:
45
+ licenses: []
46
+ metadata: {}
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 2.3.0
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubygems_version: 3.2.7
63
+ signing_key:
64
+ specification_version: 4
65
+ summary: Ruby based domain eventing tools
66
+ test_files: []