Skip to content

Commit

Permalink
Merge pull request #66 from zilverline/update-building-a-web-application
Browse files Browse the repository at this point in the history
Update example blog application from guides
  • Loading branch information
lvonk authored Dec 10, 2024
2 parents 69f27a6 + 08a753d commit 1098d96
Show file tree
Hide file tree
Showing 27 changed files with 253 additions and 221 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- 5432:5432
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Ruby
uses: ruby/setup-ruby@v1
Expand Down
2 changes: 1 addition & 1 deletion building-a-web-application/.ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.2.2
3.3.5
10 changes: 4 additions & 6 deletions building-a-web-application/Gemfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby "3.2.2"
ruby file: ".ruby-version"

gem 'rake'
# let's use the latest and greatest
gem 'sequent', github: 'zilverline/sequent'
gem 'sequent'

gem 'sinatra'
gem 'sinatra-flash'
gem 'sinatra-contrib'
gem 'activerecord'
gem 'activemodel'
gem 'webrick'
gem 'rackup'

group :test do
gem 'rspec'
Expand Down
157 changes: 88 additions & 69 deletions building-a-web-application/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,112 +1,131 @@
GIT
remote: https://github.com/zilverline/sequent.git
revision: 498812fb86edd319310be5b6ea2d53719e81cf14
specs:
sequent (7.0.1)
activemodel (>= 5.0, < 7.2)
activerecord (>= 5.0, < 7.2)
bcrypt (~> 3.1)
i18n
oj (~> 3)
parallel (~> 1.20)
parser (>= 2.6.5, < 3.3)
pg (~> 1.2)
postgresql_cursor (~> 0.6)
thread_safe (~> 0.3.6)
tzinfo (~> 2.0)

GEM
remote: https://rubygems.org/
specs:
activemodel (7.0.8)
activesupport (= 7.0.8)
activerecord (7.0.8)
activemodel (= 7.0.8)
activesupport (= 7.0.8)
activesupport (7.0.8)
concurrent-ruby (~> 1.0, >= 1.0.2)
activemodel (7.2.1.1)
activesupport (= 7.2.1.1)
activerecord (7.2.1.1)
activemodel (= 7.2.1.1)
activesupport (= 7.2.1.1)
timeout (>= 0.4.0)
activesupport (7.2.1.1)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.3.1)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
logger (>= 1.4.2)
minitest (>= 5.1)
tzinfo (~> 2.0)
securerandom (>= 0.3)
tzinfo (~> 2.0, >= 2.0.5)
ast (2.4.2)
bcrypt (3.1.19)
concurrent-ruby (1.2.2)
database_cleaner (2.0.1)
database_cleaner-active_record (~> 2.0.0)
database_cleaner-active_record (2.0.1)
base64 (0.2.0)
bcrypt (3.1.20)
bigdecimal (3.1.8)
concurrent-ruby (1.3.4)
connection_pool (2.4.1)
database_cleaner (2.0.2)
database_cleaner-active_record (>= 2, < 3)
database_cleaner-active_record (2.2.0)
activerecord (>= 5.a)
database_cleaner-core (~> 2.0.0)
database_cleaner-core (2.0.1)
diff-lcs (1.5.0)
i18n (1.14.1)
diff-lcs (1.5.1)
drb (2.2.1)
i18n (1.14.6)
concurrent-ruby (~> 1.0)
minitest (5.20.0)
logger (1.6.1)
minitest (5.25.1)
multi_json (1.15.0)
mustermann (3.0.0)
mustermann (3.0.3)
ruby2_keywords (~> 0.0.1)
oj (3.16.1)
parallel (1.23.0)
parser (3.2.2.4)
oj (3.16.6)
bigdecimal (>= 3.0)
ostruct (>= 0.2)
ostruct (0.6.0)
parallel (1.26.3)
parser (3.3.5.0)
ast (~> 2.4.1)
racc
pg (1.5.4)
postgresql_cursor (0.6.8)
pg (1.5.8)
postgresql_cursor (0.6.9)
activerecord (>= 6.0)
racc (1.7.3)
rack (2.2.8.1)
rack-protection (3.0.4)
rack
rake (13.0.6)
rspec (3.11.0)
rspec-core (~> 3.11.0)
rspec-expectations (~> 3.11.0)
rspec-mocks (~> 3.11.0)
rspec-core (3.11.0)
rspec-support (~> 3.11.0)
rspec-expectations (3.11.1)
racc (1.8.1)
rack (3.1.7)
rack-protection (4.0.0)
base64 (>= 0.1.0)
rack (>= 3.0.0, < 4)
rack-session (2.0.0)
rack (>= 3.0.0)
rackup (2.1.0)
rack (>= 3)
webrick (~> 1.8)
rake (13.2.1)
rspec (3.13.0)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
rspec-mocks (~> 3.13.0)
rspec-core (3.13.1)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.11.0)
rspec-mocks (3.11.1)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.11.0)
rspec-support (3.11.1)
rspec-support (~> 3.13.0)
rspec-support (3.13.1)
ruby2_keywords (0.0.5)
sinatra (3.0.4)
securerandom (0.3.1)
sequent (7.1.1)
activemodel (>= 6.0)
activerecord (>= 6.0)
bcrypt (~> 3.1)
i18n
oj (~> 3)
parallel (~> 1.20)
parser (>= 2.6.5, < 3.4)
pg (~> 1.2)
postgresql_cursor (~> 0.6)
thread_safe (~> 0.3.6)
tzinfo (>= 1.1)
sinatra (4.0.0)
mustermann (~> 3.0)
rack (~> 2.2, >= 2.2.4)
rack-protection (= 3.0.4)
rack (>= 3.0.0, < 4)
rack-protection (= 4.0.0)
rack-session (>= 2.0.0, < 3)
tilt (~> 2.0)
sinatra-contrib (3.0.4)
multi_json
sinatra-contrib (4.0.0)
multi_json (>= 0.0.2)
mustermann (~> 3.0)
rack-protection (= 3.0.4)
sinatra (= 3.0.4)
rack-protection (= 4.0.0)
sinatra (= 4.0.0)
tilt (~> 2.0)
sinatra-flash (0.3.0)
sinatra (>= 1.0.0)
thread_safe (0.3.6)
tilt (2.2.0)
tilt (2.4.0)
timeout (0.4.1)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
webrick (1.8.2)

PLATFORMS
ruby
arm64-darwin-23
x86_64-linux

DEPENDENCIES
activemodel
activerecord
database_cleaner
rackup
rake
rspec
sequent!
sequent
sinatra
sinatra-contrib
sinatra-flash
webrick

RUBY VERSION
ruby 3.2.2p53
ruby 3.3.5p100

BUNDLED WITH
2.1.4
2.5.21
11 changes: 2 additions & 9 deletions building-a-web-application/app/database.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
require 'sequent'

class Database
class << self
# def database_config(env = ENV['RACK_ENV'])
# @config ||= YAML.safe_load(ERB.new(File.read('db/database.yml')).result, aliases: true)[env]
# end

def establish_connection(env = ENV['RACK_ENV'])
def establish_connection(env = ENV['SEQUENT_ENV'])
Sequent::Support::Database.connect!(env)
# config = database_config(env)
# yield(config) if block_given?
# ActiveRecord::Base.configurations[env.to_s] = config.stringify_keys
# ActiveRecord::Base.establish_connection config
end
end
end
4 changes: 2 additions & 2 deletions building-a-web-application/app/projectors/author_projector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ class AuthorProjector < Sequent::Projector
on AuthorNameSet do |event|
update_all_records(
AuthorRecord,
{aggregate_id: event.aggregate_id},
{ aggregate_id: event.aggregate_id },
event.attributes.slice(:name)
)
end

on AuthorEmailSet do |event|
update_all_records(
AuthorRecord,
{aggregate_id: event.aggregate_id},
{ aggregate_id: event.aggregate_id },
event.attributes.slice(:email)
)
end
Expand Down
6 changes: 1 addition & 5 deletions building-a-web-application/app/projectors/post_projector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ class PostProjector < Sequent::Projector
end

on PostAuthorChanged do |event|
update_all_records(
PostRecord,
{aggregate_id: event.aggregate_id},
event.attributes.slice(:author_aggregate_id)
)
update_all_records(PostRecord, {aggregate_id: event.aggregate_id}, event.attributes.slice(:author_aggregate_id))
end

on PostTitleChanged do |event|
Expand Down
4 changes: 2 additions & 2 deletions building-a-web-application/app/records/author_record.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class AuthorRecord < ActiveRecord::Base
has_many :post_records, foreign_key: :author_aggregate_id, primary_key: :aggregate_id
class AuthorRecord < Sequent::ApplicationRecord
has_many :post_records, foreign_key: 'author_aggregate_id', primary_key: 'aggregate_id'
end
2 changes: 1 addition & 1 deletion building-a-web-application/app/records/post_record.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
class PostRecord < ActiveRecord::Base
class PostRecord < Sequent::ApplicationRecord
end
50 changes: 27 additions & 23 deletions building-a-web-application/app/views/authors/index.erb
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
<p>
Back to <a href="/">index</a>
</p>
<table class="table">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>E-mail</th>
</tr>
</thead>
<tbody>
<% @authors.each do |author| %>
<tr>
<td>
<a href="/authors/id/<%= author.aggregate_id %>"><%= h author.aggregate_id %></a>
</td>
<td><%= h author.name %></td>
<td><%= h author.email %></td>
</tr>
<% end %>
</tbody>
</table>
<html>
<body>
<p>
Back to <a href="/">index</a>
</p>
<table class="table">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>E-mail</th>
</tr>
</thead>
<tbody>
<% @authors.each do |author| %>
<tr>
<td>
<a href="/authors/<%= author.aggregate_id %>"><%= h author.aggregate_id %></a>
</td>
<td><%= h author.name %></td>
<td><%= h author.email %></td>
</tr>
<% end %>
</tbody>
</table>
</body>
</html>
20 changes: 10 additions & 10 deletions building-a-web-application/app/views/authors/show.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@

<table class="table">
<tbody>
<% @author.post_records.order(:id).each do |post_record| %>
<tr>
<td><%= h post_record.title %></td>
<td>
<a href="<%= "/authors/id/#{@author.aggregate_id}/post/#{post_record.aggregate_id}" %>">
<%= h post_record.aggregate_id %>
</a>
</td>
</tr>
<% end %>
<% @author.post_records.order(:id).each do |post_record| %>
<tr>
<td><%= h post_record.title %></td>
<td>
<a href="<%= "/authors/id/#{@author.aggregate_id}/post/#{post_record.aggregate_id}" %>">
<%= h post_record.aggregate_id %>
</a>
</td>
</tr>
<% end %>
</tbody>
</table>

Expand Down
Loading

0 comments on commit 1098d96

Please sign in to comment.