-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Made gem configurable, added both bootstrap5 and beercss views based …
…on configuration, added read service and specs
- Loading branch information
1 parent
f766de1
commit 2b46d15
Showing
82 changed files
with
1,144 additions
and
298 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# frozen_string_literal: true | ||
|
||
module DryModuleGenerator | ||
module Config | ||
module Configuration | ||
def configure | ||
yield self | ||
end | ||
|
||
def define_setting(name, default = nil) | ||
class_variable_set("@@#{name}", default) | ||
|
||
define_class_method "#{name}=" do |value| | ||
class_variable_set("@@#{name}", value) | ||
end | ||
|
||
define_class_method name do | ||
class_variable_get("@@#{name}") | ||
end | ||
end | ||
|
||
private | ||
|
||
def define_class_method(name, &block) | ||
(class << self; self; end).instance_eval do | ||
define_method name, &block | ||
end | ||
end | ||
end | ||
end | ||
end |
13 changes: 13 additions & 0 deletions
13
lib/dry_module_generator/config/generator_configuration.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
module DryModuleGenerator | ||
module Config | ||
module GeneratorConfiguration | ||
extend Configuration | ||
|
||
define_setting :include_views, true | ||
define_setting :css_framework, "bootstrap5" | ||
define_setting :html_style, "erb" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
14 changes: 14 additions & 0 deletions
14
lib/dry_module_generator/install/templates/app/models/aggregate_root.rb.tt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class AggregateRoot < ApplicationRecord | ||
self.abstract_class = true | ||
|
||
def domain_events | ||
@domain_events ||= [] | ||
end | ||
|
||
def apply_event(event) | ||
domain_events << event | ||
self.updated_at = DateTime.now | ||
end | ||
|
||
attr_writer :domain_events | ||
end |
11 changes: 11 additions & 0 deletions
11
lib/dry_module_generator/install/templates/app/models/application_record.rb.tt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class ApplicationRecord < ActiveRecord::Base | ||
primary_abstract_class | ||
|
||
def self.save!(record) | ||
record.tap(&:save!) | ||
end | ||
|
||
def self.delete!(record) | ||
record.tap(&:destroy!) | ||
end | ||
end |
3 changes: 3 additions & 0 deletions
3
lib/dry_module_generator/install/templates/app/models/current_user_repository.rb.tt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class CurrentUserRepository < ActiveSupport::CurrentAttributes | ||
attribute :authenticated_identity | ||
end |
20 changes: 20 additions & 0 deletions
20
lib/dry_module_generator/install/templates/app/services/application_service.rb.tt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class ApplicationService | ||
include Import[event_publisher: 'events.publisher', current_user_repository: 'current_user_repository'] | ||
include Pagy::Backend | ||
|
||
def paginate_collection(collection:, mapper:, page:, page_size:, filter:, size: 5, options: {}) | ||
result = pagy(collection.ransack(filter).result, items: page_size, page: page, size: size) | ||
|
||
pagy_metadata = result[0] | ||
paginated_data = result[1] | ||
|
||
PaginationListDto.new( | ||
data: map_into(paginated_data, mapper, options), | ||
pagination: map_into(pagy_metadata, PaginationDto) | ||
) | ||
end | ||
|
||
def map_into(data, mapper, options = {}) | ||
DryObjectMapper::Mapper.call(data, mapper, options) | ||
end | ||
end |
7 changes: 7 additions & 0 deletions
7
lib/dry_module_generator/install/templates/app/services/async_event_handler.rb.tt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class AsyncEventHandler < ApplicationJob | ||
def call(_event); end | ||
|
||
def perform(serialized_event) | ||
call(App::Container.resolve('events.publisher').deserialize(serialized_event, YAML)) | ||
end | ||
end |
3 changes: 3 additions & 0 deletions
3
lib/dry_module_generator/install/templates/app/services/async_thread_event_handler.rb.tt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Just a marker abstract class | ||
class AsyncThreadEventHandler | ||
end |
12 changes: 12 additions & 0 deletions
12
lib/dry_module_generator/install/templates/app/views/shared/_flash.html.erb.tt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<%% | ||
key = flash&.keys&.first&.to_s || "" | ||
value = flash[key] || [] | ||
value = [value] unless value.is_a?(Array) | ||
%> | ||
|
||
<div id="flash" | ||
data-controller="flash" | ||
data-flash-type-value="<%%= key %>" | ||
data-flash-message-value="<%%= value %>" | ||
> | ||
</div> |
3 changes: 3 additions & 0 deletions
3
lib/dry_module_generator/install/templates/config/initializers/active_job_serializers.rb.tt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require 'utils/command_serializer' | ||
|
||
Rails.application.config.active_job.custom_serializers << CommandSerializer |
55 changes: 55 additions & 0 deletions
55
lib/dry_module_generator/install/templates/config/initializers/container.rb.tt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
Dir[File.join(Rails.root, 'lib', 'utils', 'events', '*.rb')].each do |file| | ||
require File.join(File.dirname(file), File.basename(file, File.extname(file))) | ||
end | ||
|
||
Dir[File.join(Rails.root, 'lib', 'utils', 'concurrent', '*.rb')].each do |file| | ||
require File.join(File.dirname(file), File.basename(file, File.extname(file))) | ||
end | ||
|
||
module App | ||
class Container < Dry::System::Container | ||
register('contract_validator') { ContractValidator.new } | ||
register('current_user_repository') { CurrentUserRepository } | ||
if Rails.env.test? | ||
register('events.client', RailsEventStore::Client.new( | ||
repository: NoOpEventRepository.new, | ||
mapper: ToYAMLEventMapper.new, | ||
dispatcher: RubyEventStore::ComposedDispatcher.new( | ||
RailsEventStore::ImmediateAsyncDispatcher.new(scheduler: ImmediateActiveJobEventScheduler.new(serializer: YAML)), | ||
RailsEventStore::ImmediateAsyncDispatcher.new(scheduler: ImmediateEventScheduler.new(event_deserializer: YAML)) | ||
) | ||
)) | ||
else | ||
register('events.client', RailsEventStore::Client.new( | ||
repository: NoOpEventRepository.new, | ||
mapper: ToYAMLEventMapper.new, | ||
dispatcher: RubyEventStore::ComposedDispatcher.new( | ||
RailsEventStore::ImmediateAsyncDispatcher.new(scheduler: ActiveJobEventScheduler.new(serializer: YAML)), | ||
RailsEventStore::ImmediateAsyncDispatcher.new( | ||
scheduler: AsyncThreadEventScheduler.new( | ||
job_scheduler: AsyncJobScheduler.new( | ||
executor_service: Concurrent::ThreadPoolExecutor.new( | ||
min_threads: 1, | ||
max_threads: (ENV['BACKGROUND_THREADS'] || 5).to_i, | ||
max_queue: ENV['BACKGROUND_TASK_POOL_SIZE'].to_i, | ||
fallback_policy: :caller_runs | ||
) | ||
), | ||
event_deserializer: YAML | ||
) | ||
) | ||
) | ||
)) | ||
end | ||
|
||
register('events.publisher', memoize: true) { MetadataEventPublisher.new } | ||
end | ||
end | ||
|
||
Import = App::Container.injector | ||
|
||
Rails.configuration.after_initialize do | ||
Dir[File.join(Rails.root, '*', 'lib', '*', 'infra', 'system', 'provider_source.rb')].each do |file| | ||
require File.join(File.dirname(file), File.basename(file, File.extname(file))) | ||
end | ||
end |
2 changes: 2 additions & 0 deletions
2
...s/initializers/dependency_injection.rb.tt → ...g/initializers/dependency_injection.rb.tt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
require 'utils/injection/active_job_strategy' | ||
require 'utils/injection/controller_resolve_strategy' | ||
|
||
Dry::AutoInject::Strategies.register('active_job', Dry::AutoInject::Strategies::ActiveJobStrategy) | ||
Dry::AutoInject::Strategies.register('inject', Dry::AutoInject::Strategies::ControllerResolveStrategy) |
Oops, something went wrong.