fourth_dimensional 0.1.0
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 +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +15 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +39 -0
- data/README.md +123 -0
- data/Rakefile +16 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/fourth_dimensional.gemspec +31 -0
- data/lib/fourth_dimensional/event.rb +54 -0
- data/lib/fourth_dimensional/version.rb +3 -0
- data/lib/fourth_dimensional.rb +7 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 11c3860996942f56fa43873961fdbbf82069813122122326a29d286d33455990
|
4
|
+
data.tar.gz: 42f4c00c835316f5e0fe04a42e699afb25ef758c5e4d6ed3a87242c9eccd2567
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 55df185870d5e5f68b6cf6bd68c83b69e54ec1e3bc606e5568574387a95a441f7c4b75245f9f29e53d3d2916fb18a0b8d34b330a40e7581b80287cc22f9315c9
|
7
|
+
data.tar.gz: c7a17815b197d2a9767714a002b148e54c2fac6fdb7d3f4094ccd132308899d7e96dfd6f8fcb856eb0397ab6db00686cdba009c20b4d7e121a28c2450a9496f3
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
sudo: false
|
3
|
+
language: ruby
|
4
|
+
cache: bundler
|
5
|
+
rvm:
|
6
|
+
- 2.6.1
|
7
|
+
before_install: gem install bundler -v 1.17.2
|
8
|
+
deploy:
|
9
|
+
local-dir: ./doc
|
10
|
+
provider: pages
|
11
|
+
skip-cleanup: true
|
12
|
+
github-token: $GITHUB_TOKEN
|
13
|
+
keep-history: true
|
14
|
+
on:
|
15
|
+
branch: master
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
fourth_dimensional (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.3)
|
10
|
+
rake (10.5.0)
|
11
|
+
rdoc (6.1.1)
|
12
|
+
rspec (3.8.0)
|
13
|
+
rspec-core (~> 3.8.0)
|
14
|
+
rspec-expectations (~> 3.8.0)
|
15
|
+
rspec-mocks (~> 3.8.0)
|
16
|
+
rspec-core (3.8.0)
|
17
|
+
rspec-support (~> 3.8.0)
|
18
|
+
rspec-expectations (3.8.2)
|
19
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
20
|
+
rspec-support (~> 3.8.0)
|
21
|
+
rspec-mocks (3.8.0)
|
22
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
23
|
+
rspec-support (~> 3.8.0)
|
24
|
+
rspec-support (3.8.0)
|
25
|
+
sdoc (1.0.0)
|
26
|
+
rdoc (>= 5.0)
|
27
|
+
|
28
|
+
PLATFORMS
|
29
|
+
ruby
|
30
|
+
|
31
|
+
DEPENDENCIES
|
32
|
+
bundler (~> 1.17)
|
33
|
+
fourth_dimensional!
|
34
|
+
rake (~> 10.0)
|
35
|
+
rspec (~> 3.0)
|
36
|
+
sdoc (~> 1.0)
|
37
|
+
|
38
|
+
BUNDLED WITH
|
39
|
+
1.17.2
|
data/README.md
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
# Fourth Dimensional
|
2
|
+
|
3
|
+
Fourth Dimensional is an event sourcing library to account for the state of a
|
4
|
+
system in relation to time.
|
5
|
+
|
6
|
+
This project is a lightweight dsl for commands and events for use with
|
7
|
+
ActiveRecord. Eventually I'd like it to support Sequel as well.
|
8
|
+
|
9
|
+
[RDoc][rdoc_url]
|
10
|
+
|
11
|
+
[![Build Status]][travis_status]
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'fourth_dimensional'
|
19
|
+
```
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
$ bundle
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
$ gem install fourth_dimensional
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
This API is in flux, but here's the general idea.
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
class PostAdded < FourthDimensional::Event
|
35
|
+
def title
|
36
|
+
data.fetch('title')
|
37
|
+
end
|
38
|
+
|
39
|
+
def body
|
40
|
+
data.fetch('body')
|
41
|
+
end
|
42
|
+
|
43
|
+
def published
|
44
|
+
data.fetch('published')
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class AddPost < FourthDimensional::Command
|
49
|
+
attributes :title, :body, :published
|
50
|
+
validates_presence_of :title, :body
|
51
|
+
end
|
52
|
+
|
53
|
+
class PostCommandHandler < FourthDimensional::CommandHandler
|
54
|
+
on AddPost do |command|
|
55
|
+
with_aggregate(PostAggregate, command) do |post|
|
56
|
+
post.add(title: command.title,
|
57
|
+
body: command.body,
|
58
|
+
published: command.published)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
class PostAggregate < FourthDimensional::AggregateRoot
|
64
|
+
def add(title:, body:, published:)
|
65
|
+
apply(PostAdded,
|
66
|
+
data: {
|
67
|
+
title: title,
|
68
|
+
body: body,
|
69
|
+
published: published
|
70
|
+
}
|
71
|
+
)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
class PostProjector < FourthDimensional::RecordProjector
|
76
|
+
self.record_class = 'Post'
|
77
|
+
|
78
|
+
on PostAdded do |event|
|
79
|
+
record.title = event.title
|
80
|
+
record.body = event.body
|
81
|
+
record.published = event.published
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def main
|
86
|
+
FourthDimensional.configure do |config|
|
87
|
+
config.event_handlers = [
|
88
|
+
PostCommandHandler,
|
89
|
+
PostProjector
|
90
|
+
]
|
91
|
+
end
|
92
|
+
|
93
|
+
aggregate_id = SecureRandom.uuid
|
94
|
+
|
95
|
+
command = AddPost.new(aggregate_id: aggregate_id,
|
96
|
+
title: 'post-title',
|
97
|
+
body: 'post-body',
|
98
|
+
published: true)
|
99
|
+
|
100
|
+
# persists command and event if successful
|
101
|
+
FourthDimensional.execute_commands(command)
|
102
|
+
|
103
|
+
post = Post.find(aggregate_id)
|
104
|
+
expect(post.title).to eq('post-title')
|
105
|
+
expect(post.body).to eq('post-body')
|
106
|
+
expect(post.published).to be_truthy
|
107
|
+
end
|
108
|
+
```
|
109
|
+
|
110
|
+
## Development
|
111
|
+
|
112
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
113
|
+
|
114
|
+
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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
115
|
+
|
116
|
+
## Contributing
|
117
|
+
|
118
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/baylorrae/fourth_dimensional.
|
119
|
+
|
120
|
+
[rdoc_url]: https://baylorrae.com/fourth_dimensional
|
121
|
+
|
122
|
+
[Build Status]: https://travis-ci.org/BaylorRae/fourth_dimensional.svg?branch=master
|
123
|
+
[travis_status]: https://travis-ci.org/BaylorRae/fourth_dimensional
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
3
|
+
require "sdoc"
|
4
|
+
require "rdoc/task"
|
5
|
+
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
7
|
+
|
8
|
+
RDoc::Task.new do |rdoc|
|
9
|
+
rdoc.rdoc_dir = 'doc'
|
10
|
+
rdoc.options << '--format=sdoc'
|
11
|
+
rdoc.options << '--github'
|
12
|
+
rdoc.main = 'README.md'
|
13
|
+
rdoc.rdoc_files.include('README.md', 'lib/**/*.rb')
|
14
|
+
end
|
15
|
+
|
16
|
+
task :default => [:spec, :rdoc]
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "fourth_dimensional"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "fourth_dimensional/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "fourth_dimensional"
|
8
|
+
spec.version = FourthDimensional::VERSION
|
9
|
+
spec.authors = ["Baylor Rae'"]
|
10
|
+
spec.email = ["baylor@thecodedeli.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Fourth Dimensional is an event sourcing library to account for the state of a
|
13
|
+
system in relation to time.}
|
14
|
+
spec.description = %q{Fourth Dimensional is an event sourcing library to account for the state of a
|
15
|
+
system in relation to time.}
|
16
|
+
spec.homepage = "https://github.com/baylorrae/fourth_dimensional"
|
17
|
+
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
end
|
23
|
+
spec.bindir = "exe"
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
30
|
+
spec.add_development_dependency "sdoc", "~> 1.0"
|
31
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module FourthDimensional
|
2
|
+
# == FourthDimensional::Event
|
3
|
+
#
|
4
|
+
# Events act as a log primarily focused around an aggregate. When persisted it
|
5
|
+
# will use the underscored version of the class name as the +event_type+.
|
6
|
+
#
|
7
|
+
# module Posts
|
8
|
+
# PostAdded = Class.new(FourthDimensional::Event)
|
9
|
+
# end
|
10
|
+
#
|
11
|
+
# It is recommended practice to add delegating methods to the attributes
|
12
|
+
# within +data+. These aliases will make it easier to see what's being stored
|
13
|
+
# from the codebase.
|
14
|
+
#
|
15
|
+
# module Posts
|
16
|
+
# class PostAdded < FourthDimensional::Event
|
17
|
+
# def title
|
18
|
+
# data.fetch('title')
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# def body
|
22
|
+
# data.fetch('body')
|
23
|
+
# end
|
24
|
+
# end
|
25
|
+
# end
|
26
|
+
class Event
|
27
|
+
attr_reader :aggregate_id
|
28
|
+
|
29
|
+
# hash of data with stringified keys
|
30
|
+
attr_reader :data, :metadata
|
31
|
+
|
32
|
+
# Initializes an event with the required +aggregate_id+ and optional +data+
|
33
|
+
# and +metadata+.
|
34
|
+
#
|
35
|
+
# event = MyEvent.new(aggregate_id: '1-2-3')
|
36
|
+
# event.aggregate_id # => '1-2-3'
|
37
|
+
# event.data # => {}
|
38
|
+
# event.metadata # => {}
|
39
|
+
#
|
40
|
+
# +data+ and +metadata+ should be hashes and the keys will transformed into
|
41
|
+
# strings to accommodate deserializing the values from json.
|
42
|
+
#
|
43
|
+
# event = MyEvent.new(aggregate_id: '1-2-3',
|
44
|
+
# data: { one: 1 },
|
45
|
+
# metadata: { two: 2 })
|
46
|
+
# event.data # => { 'one' => 1 }
|
47
|
+
# event.metadata # => { 'two' => 2 }
|
48
|
+
def initialize(aggregate_id:, data: nil, metadata: nil)
|
49
|
+
@aggregate_id = aggregate_id
|
50
|
+
@data = data || {}
|
51
|
+
@metadata = metadata || {}
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fourth_dimensional
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Baylor Rae'
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-02-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.17'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.17'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sdoc
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.0'
|
69
|
+
description: |-
|
70
|
+
Fourth Dimensional is an event sourcing library to account for the state of a
|
71
|
+
system in relation to time.
|
72
|
+
email:
|
73
|
+
- baylor@thecodedeli.com
|
74
|
+
executables: []
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- ".gitignore"
|
79
|
+
- ".rspec"
|
80
|
+
- ".travis.yml"
|
81
|
+
- Gemfile
|
82
|
+
- Gemfile.lock
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- bin/console
|
86
|
+
- bin/setup
|
87
|
+
- fourth_dimensional.gemspec
|
88
|
+
- lib/fourth_dimensional.rb
|
89
|
+
- lib/fourth_dimensional/event.rb
|
90
|
+
- lib/fourth_dimensional/version.rb
|
91
|
+
homepage: https://github.com/baylorrae/fourth_dimensional
|
92
|
+
licenses: []
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubygems_version: 3.0.1
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: Fourth Dimensional is an event sourcing library to account for the state
|
113
|
+
of a system in relation to time.
|
114
|
+
test_files: []
|