unity-dynamodbstreams-event-processor 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0e4aaea448a677bac4ddede1d525151102e8b211307e522038b3a5353719da56
4
+ data.tar.gz: 6ab4fed762778f50d503d31ed18b08dc3edacf2c92cac7e0e39a19a76937d866
5
+ SHA512:
6
+ metadata.gz: c62049c49536734634a0f0c3846e539f15cfd2db31c8e114003ebd58d53f197efc84a5490ec3d407df89b59562ef89f0d740bbf758700e35f24fc5cd04d82501
7
+ data.tar.gz: 21f768a1ebbb19d43fd9fa2af4f7cfd52ccf7d2903533782bf116b06a297ff84330f4942308eaef991d0ea54b997ef4e5c5eedc8a8657a3356a3182e985eb0a8
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /*.gem
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in unity-dynamodb_stream_worker.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,39 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ unity-dynamodbstreams-event-processor (1.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ aws-eventstream (1.2.0)
10
+ aws-partitions (1.497.0)
11
+ aws-sdk-core (3.121.0)
12
+ aws-eventstream (~> 1, >= 1.0.2)
13
+ aws-partitions (~> 1, >= 1.239.0)
14
+ aws-sigv4 (~> 1.1)
15
+ jmespath (~> 1.0)
16
+ aws-sdk-dynamodbstreams (1.29.0)
17
+ aws-sdk-core (~> 3, >= 3.112.0)
18
+ aws-sigv4 (~> 1.1)
19
+ aws-sigv4 (1.4.0)
20
+ aws-eventstream (~> 1, >= 1.0.2)
21
+ jmespath (1.4.0)
22
+ ox (2.14.5)
23
+ rake (13.0.6)
24
+ unity-dynamodb-attribute-deserializer (1.0.0)
25
+ unity-dynamodbstreams-event-parser (1.0.0)
26
+ unity-dynamodb-attribute-deserializer (~> 1.0)
27
+
28
+ PLATFORMS
29
+ x86_64-darwin-20
30
+
31
+ DEPENDENCIES
32
+ aws-sdk-dynamodbstreams (~> 1.0)
33
+ ox (~> 2.14)
34
+ rake (~> 13.0)
35
+ unity-dynamodbstreams-event-parser (~> 1.0)
36
+ unity-dynamodbstreams-event-processor!
37
+
38
+ BUNDLED WITH
39
+ 2.2.3
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Unity::DynamodbStreamWorker
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/unity/dynamodb_stream_worker`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'unity-dynamodb_stream_worker'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install unity-dynamodb_stream_worker
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/unity-dynamodb_stream_worker.
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "unity/dynamodbstreams/event_processor"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/example.rb ADDED
@@ -0,0 +1,36 @@
1
+ require "bundler/setup"
2
+ require 'unity-dynamodbstreams-event-parser'
3
+ require "unity-dynamodbstreams-event-processor"
4
+
5
+ class TestHandler
6
+ def call(event)
7
+ puts event
8
+ end
9
+ end
10
+
11
+ event = {
12
+ 'eventID' => '1',
13
+ 'eventName' => 'INSERT',
14
+ 'eventVersion' => '1.0',
15
+ 'eventSource' => 'aws:dynamodb',
16
+ 'awsRegion' => 'us-east-1',
17
+ 'dynamodb' => {
18
+ 'Keys' => { 'id' => { 'N' => '101' } },
19
+ 'NewImage' => {
20
+ 'id' => { 'N' => '101' },
21
+ 'message' => { 'S' => 'Hello world!' }
22
+ },
23
+ 'SequenceNumber' => '111',
24
+ 'SizeBytes' => 26,
25
+ 'StreamViewType' => 'NEW_AND_OLD_IMAGES',
26
+ 'ApproximateCreationDateTime' => 1633768788
27
+ },
28
+ 'eventSourceARN' => 'arn:aws:dynamodb:us-east-1:111122223333:table/TestTable/stream/2015–05–11T21:21:33.291'
29
+ }
30
+ event_parser = Unity::DynamoDBStreams::EventParser.new
31
+ event_processor = Unity::DynamoDBStreams::EventProcessor.new do
32
+ table 'TestTable' do
33
+ on_insert TestHandler.new
34
+ end
35
+ end
36
+ event_processor.process(event_parser.call(event))
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unity
4
+ module DynamoDBStreams
5
+ class EventProcessor
6
+ VERSION = '1.0.1'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'event_processor/version'
4
+ require 'aws-sdk-dynamodbstreams'
5
+
6
+ module Unity
7
+ module DynamoDBStreams
8
+ class EventProcessor
9
+ HOOK_TYPES = {
10
+ 'INSERT' => :insert,
11
+ 'REMOVE' => :remove,
12
+ 'MODIFY' => :update
13
+ }.freeze
14
+
15
+ def self.table_handlers
16
+ @table_handlers ||= {}
17
+ end
18
+
19
+ def initialize(&block)
20
+ @table_handlers = {}
21
+ instance_exec(&block) if block_given?
22
+ end
23
+
24
+ def table(table_name, &block)
25
+ @table_handlers[table_name] ||= TableHandler.new
26
+ @table_handlers[table_name].instance_exec(&block)
27
+ end
28
+
29
+ def parse(str)
30
+ @event_parser.call(str)
31
+ end
32
+
33
+ def process(event)
34
+ event_source_arn_split = event.event_source_arn.split(':', 6)
35
+ table_name = event_source_arn_split[5].split('/').at(1)
36
+ return unless @table_handlers.key?(table_name)
37
+
38
+ hook_type = HOOK_TYPES[event.event_name]
39
+ return if hook_type.nil?
40
+
41
+ @table_handlers[table_name].each(hook_type) do |handler|
42
+ handler.call(event)
43
+ end
44
+
45
+ true
46
+ end
47
+
48
+ class TableHandler
49
+ def initialize
50
+ @handlers = { insert: [], remove: [], update: [] }
51
+ end
52
+
53
+ def on(type, handler = nil, &block)
54
+ @handlers[type] << handler || block
55
+ end
56
+
57
+ def on_insert(handler = nil, &block)
58
+ on(:insert, handler || block)
59
+ end
60
+
61
+ def on_remove(handler = nil, &block)
62
+ on(:remove, handler || block)
63
+ end
64
+
65
+ def on_update(handler = nil, &block)
66
+ on(:update, handler || block)
67
+ end
68
+
69
+ def each(type, &block)
70
+ @handlers[type].each(&block)
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1 @@
1
+ require 'unity/dynamodbstreams/event_processor'
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/unity/dynamodbstreams/event_processor/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'unity-dynamodbstreams-event-processor'
7
+ spec.version = Unity::DynamoDBStreams::EventProcessor::VERSION
8
+ spec.authors = ["Julien D."]
9
+ spec.email = ["julien@pocketsizesun.com"]
10
+
11
+ spec.summary = 'DynamoDB Streams - Event Processor'
12
+ spec.description = 'DynamoDB Streams - Event Processor'
13
+ spec.homepage = 'https://github.com/pocketsizesun/unity-dynamodbstreams-event-processor-ruby'
14
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
15
+
16
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
17
+
18
+ spec.metadata['homepage_uri'] = spec.homepage
19
+ spec.metadata['source_code_uri'] = 'https://github.com/pocketsizesun/unity-dynamodbstreams-event-processor-ruby'
20
+ spec.metadata['changelog_uri'] = 'https://github.com/pocketsizesun/unity-dynamodbstreams-event-processor-ruby'
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
26
+ end
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ # Uncomment to register a new dependency of your gem
32
+ spec.add_development_dependency 'unity-dynamodbstreams-event-parser', '~> 1.0'
33
+ spec.add_development_dependency 'ox', '~> 2.14'
34
+ spec.add_development_dependency 'aws-sdk-dynamodbstreams', '~> 1.0'
35
+
36
+ # For more information and examples about making a new gem, checkout our
37
+ # guide at: https://bundler.io/guides/creating_gem.html
38
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: unity-dynamodbstreams-event-processor
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Julien D.
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-10-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: unity-dynamodbstreams-event-parser
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: ox
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.14'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.14'
41
+ - !ruby/object:Gem::Dependency
42
+ name: aws-sdk-dynamodbstreams
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ description: DynamoDB Streams - Event Processor
56
+ email:
57
+ - julien@pocketsizesun.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - Gemfile.lock
65
+ - README.md
66
+ - Rakefile
67
+ - bin/console
68
+ - bin/setup
69
+ - example.rb
70
+ - lib/unity-dynamodbstreams-event-processor.rb
71
+ - lib/unity/dynamodbstreams/event_processor.rb
72
+ - lib/unity/dynamodbstreams/event_processor/version.rb
73
+ - unity-dynamodbstreams-event-processor.gemspec
74
+ homepage: https://github.com/pocketsizesun/unity-dynamodbstreams-event-processor-ruby
75
+ licenses: []
76
+ metadata:
77
+ allowed_push_host: https://rubygems.org
78
+ homepage_uri: https://github.com/pocketsizesun/unity-dynamodbstreams-event-processor-ruby
79
+ source_code_uri: https://github.com/pocketsizesun/unity-dynamodbstreams-event-processor-ruby
80
+ changelog_uri: https://github.com/pocketsizesun/unity-dynamodbstreams-event-processor-ruby
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 2.3.0
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubygems_version: 3.2.3
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: DynamoDB Streams - Event Processor
100
+ test_files: []