dry_module_generator 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +3 -0
  3. data/.rubocop.yml +40 -0
  4. data/CHANGELOG.md +5 -0
  5. data/CODE_OF_CONDUCT.md +84 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +85 -0
  8. data/Rakefile +12 -0
  9. data/lib/dry_module_generator/install/USAGE +0 -0
  10. data/lib/dry_module_generator/install/installer.rb +145 -0
  11. data/lib/dry_module_generator/install/templates/errors/constraint_error.rb.tt +7 -0
  12. data/lib/dry_module_generator/install/templates/initializers/container.rb.tt +13 -0
  13. data/lib/dry_module_generator/install/templates/initializers/dependency_injection.rb.tt +3 -0
  14. data/lib/dry_module_generator/install/templates/initializers/dry_struct_generator.rb.tt +5 -0
  15. data/lib/dry_module_generator/install/templates/initializers/routes.rb.tt +1 -0
  16. data/lib/dry_module_generator/install/templates/javascript/controllers/form_controller.js.tt +14 -0
  17. data/lib/dry_module_generator/install/templates/services/application_service.rb.tt +5 -0
  18. data/lib/dry_module_generator/install/templates/utils/application_contract.rb.tt +32 -0
  19. data/lib/dry_module_generator/install/templates/utils/application_read_struct.rb.tt +3 -0
  20. data/lib/dry_module_generator/install/templates/utils/application_struct.rb.tt +25 -0
  21. data/lib/dry_module_generator/install/templates/utils/contract_validator.rb.tt +12 -0
  22. data/lib/dry_module_generator/install/templates/utils/injection/controller_resolve_strategy.rb.tt +45 -0
  23. data/lib/dry_module_generator/install/templates/utils/types.rb.tt +3 -0
  24. data/lib/dry_module_generator/module/USAGE +8 -0
  25. data/lib/dry_module_generator/module/generator.rb +165 -0
  26. data/lib/dry_module_generator/module/templates/app/details_dto.rb.tt +10 -0
  27. data/lib/dry_module_generator/module/templates/app/list_dto.rb.tt +10 -0
  28. data/lib/dry_module_generator/module/templates/app/service.rb.tt +37 -0
  29. data/lib/dry_module_generator/module/templates/domain/model.rb.tt +9 -0
  30. data/lib/dry_module_generator/module/templates/infra/config/application.rb.tt +5 -0
  31. data/lib/dry_module_generator/module/templates/infra/config/routes.rb.tt +5 -0
  32. data/lib/dry_module_generator/module/templates/infra/db/migrate/migration.rb.tt +12 -0
  33. data/lib/dry_module_generator/module/templates/infra/system/provider_source.rb.tt +11 -0
  34. data/lib/dry_module_generator/module/templates/spec/ui/validation_test.rb.tt +25 -0
  35. data/lib/dry_module_generator/module/templates/ui/controller.rb.tt +53 -0
  36. data/lib/dry_module_generator/module/templates/ui/create_validation.rb.tt +11 -0
  37. data/lib/dry_module_generator/module/templates/ui/update_validation.rb.tt +15 -0
  38. data/lib/dry_module_generator/module/templates/ui/views/edit.rb.tt +6 -0
  39. data/lib/dry_module_generator/module/templates/ui/views/form.rb.tt +12 -0
  40. data/lib/dry_module_generator/module/templates/ui/views/index.rb.tt +36 -0
  41. data/lib/dry_module_generator/module/templates/ui/views/new.rb.tt +7 -0
  42. data/lib/dry_module_generator/module/templates/ui/views/show.rb.tt +16 -0
  43. data/lib/dry_module_generator/railtie.rb +12 -0
  44. data/lib/dry_module_generator/version.rb +5 -0
  45. data/lib/dry_module_generator.rb +11 -0
  46. data/sig/dry_module_generator.rbs +4 -0
  47. metadata +109 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a325da4a25ab25933be0769b88783b19414228609f7d203c65700373eec5c3c9
4
+ data.tar.gz: 4aec1c4ab6965c11ef03f1f497e0caaa6e99ced3c24afe754afb6512b2b53b39
5
+ SHA512:
6
+ metadata.gz: ba5feb523d93bc9136762c71213ecb12984d3b90a2ed1ca739e4bc779df98822cd9c71f51a7d5a067764be2dcd557c617d1d3d40b3dfc91b93eaf41d5bbebb45
7
+ data.tar.gz: 84ae25906793f4da6c276ea07dabdac826936370bf03fc5cd45cf11b708a88f267990f7cbfcf5a6be3348cfd9fb507f224f094dd69b9ef72eaa08c4f8227a13a
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,40 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+ Exclude:
4
+ - 'spec/**/*.rb'
5
+ - 'vendor/bundle/**/*'
6
+
7
+ Style/StringLiterals:
8
+ Enabled: true
9
+ EnforcedStyle: double_quotes
10
+
11
+ Style/StringLiteralsInInterpolation:
12
+ Enabled: true
13
+ EnforcedStyle: double_quotes
14
+
15
+ Layout/LineLength:
16
+ Max: 120
17
+
18
+ Metrics/MethodLength:
19
+ Max: 50
20
+
21
+ Documentation:
22
+ Enabled: false
23
+
24
+ Metrics/AbcSize:
25
+ Enabled: false
26
+
27
+ Metrics/BlockLength:
28
+ Max: 40
29
+
30
+ Metrics/ClassLength:
31
+ Max: 200
32
+
33
+ Metrics/PerceivedComplexity:
34
+ Max: 15
35
+
36
+ Metrics/CyclomaticComplexity:
37
+ Max: 15
38
+
39
+ Style/ClassVars:
40
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2024-01-18
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at janeterziev@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Jane-Terziev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,85 @@
1
+ # DryModuleGenerator
2
+
3
+ A custom generator for creating features as modules using the dry.rb gems. The module registers a dry system provider,
4
+ adds routes, view and migrations paths to the application configuration and registers the models and services for
5
+ dependency injection.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'dry_module_generator'
13
+ ```
14
+
15
+ Intall the gem
16
+
17
+ bundle install
18
+
19
+ Then run the setup generator which adds all the utilities and
20
+ configurations to your project:
21
+
22
+ rails g dry_module:setup
23
+
24
+ ## Usage
25
+ Run the following command in the terminal:
26
+
27
+ rails g dry_module module_name
28
+ --attributes attribute1:string:required
29
+ attribute2:integer:optional
30
+ attribute3:boolean:optional
31
+
32
+ Separate your attributes with spaces.
33
+ The attributes are sent in the following format: attribute_name:type:(required/optional).
34
+
35
+ The supported attribute types are: string, integer, float, boolean, array, date, datetime, time.
36
+
37
+ This will generate a folder in your root path with the following structure:
38
+
39
+ root
40
+ module_name
41
+ - lib
42
+ - module_name
43
+ - app
44
+ - service.rb
45
+ - list_dto.rb
46
+ - details_dto.rb
47
+ - domain
48
+ - model.rb
49
+ - infra
50
+ - config
51
+ - db
52
+ - migrations
53
+ - migration_file.rb
54
+ - system
55
+ - provider_source.rb
56
+ - ui
57
+ - views
58
+ - _form.html.erb
59
+ - index.html.erb
60
+ - edit.html.erb
61
+ - show.html.erb
62
+ - new.html.erb
63
+ - create_validation.rb
64
+ - update_validation.rb
65
+ - controller.rb
66
+
67
+
68
+ ## Development
69
+
70
+ 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.
71
+
72
+ 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).
73
+
74
+ ## Contributing
75
+
76
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Jane-Terziev/dry_module_generator. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/dry_module_generator/blob/master/CODE_OF_CONDUCT.md).
77
+
78
+
79
+ ## License
80
+
81
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
82
+
83
+ ## Code of Conduct
84
+
85
+ Everyone interacting in the DryModuleGenerator project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/dry_module_generator/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
File without changes
@@ -0,0 +1,145 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DryModuleGenerator
4
+ class Installer < Rails::Generators::Base
5
+ source_root File.expand_path("templates", __dir__)
6
+ namespace "dry_module:setup"
7
+
8
+ def update_application_record
9
+ file_path = "app/models/application_record.rb"
10
+ class_name = "ApplicationRecord"
11
+
12
+ # Read the existing content of the file
13
+ file_content = File.read(file_path)
14
+
15
+ # Define the code you want to add
16
+ additional_code = "
17
+
18
+ def self.save(record)
19
+ record.tap(&:save)
20
+ end
21
+
22
+ def self.save!(record)
23
+ record.tap(&:save!)
24
+ end
25
+
26
+ def self.delete!(record)
27
+ record.tap(&:destroy!)
28
+ end"
29
+
30
+ # Check if the class is present in the file
31
+ if file_content.include?("class #{class_name}") && !file_content.include?("def self.save!")
32
+ # If the class is present, find the end of the class definition and add the code there
33
+ class_definition_end = file_content.index("end", file_content.index("class #{class_name}"))
34
+ if class_definition_end
35
+ inject_code_position = class_definition_end - 1
36
+ file_content.insert(inject_code_position, additional_code)
37
+ File.write(file_path, file_content)
38
+ else
39
+ puts "Error: Unable to find the end of the class definition in #{file_path}."
40
+ end
41
+ else
42
+ puts "Error: Unable to find the class definition for #{class_name} in #{file_path}."
43
+ end
44
+ end
45
+
46
+ def create_utils
47
+ template("utils/contract_validator.rb", File.join("lib/utils/contract_validator.rb"))
48
+ template("utils/types.rb", File.join("lib/utils/types.rb"))
49
+ template("utils/application_contract.rb", File.join("lib/utils/application_contract.rb"))
50
+ template("utils/application_struct.rb", File.join("lib/utils/application_struct.rb"))
51
+ template("utils/application_read_struct.rb", File.join("lib/utils/application_read_struct.rb"))
52
+ template(
53
+ "utils/injection/controller_resolve_strategy.rb",
54
+ File.join("lib/utils/injection/controller_resolve_strategy.rb")
55
+ )
56
+ end
57
+
58
+ def create_application_service
59
+ template("services/application_service.rb", File.join("app/services/application_service.rb"))
60
+ end
61
+
62
+ def create_constraint_error
63
+ template("errors/constraint_error.rb", File.join("app/errors/constraint_error.rb"))
64
+ end
65
+
66
+ def create_initializers
67
+ template("initializers/container.rb", File.join("config/initializers/container.rb"))
68
+ template("initializers/dependency_injection.rb", File.join("config/initializers/dependency_injection.rb"))
69
+ template("initializers/dry_struct_generator.rb", File.join("config/initializers/dry_struct_generator.rb"))
70
+ template("initializers/routes.rb", File.join("config/initializers/routes.rb"))
71
+ end
72
+
73
+ def update_application
74
+ inject_into_file "config/application.rb" do
75
+ "
76
+ Dir[File.join(Rails.root, '*', 'lib', '*', 'infra', 'config', 'application.rb')].each do |file|
77
+ require File.join(File.dirname(file), File.basename(file, File.extname(file)))
78
+ end
79
+ "
80
+ end
81
+ end
82
+
83
+ def update_application_controller
84
+ file_path = "app/controllers/application_controller.rb"
85
+ file_content = File.read(file_path)
86
+
87
+ return if file_content.include?("ConstraintError")
88
+
89
+ inject_into_class file_path, "ApplicationController" do
90
+ " include Import.inject[validator: 'contract_validator']
91
+
92
+ rescue_from(ConstraintError) do |e|
93
+ @form = e.validator
94
+ if action_name == 'create'
95
+ render :new, status: :unprocessable_entity
96
+ elsif action_name == 'update'
97
+ render :edit, status: :unprocessable_entity
98
+ end
99
+ end
100
+
101
+ "
102
+ end
103
+ end
104
+
105
+ def update_application_helper
106
+ file_path = "app/helpers/application_helper.rb"
107
+ file_content = File.read(file_path)
108
+
109
+ return if file_content.include?("def show_error")
110
+
111
+ inject_into_module file_path, "ApplicationHelper" do
112
+ <<-"CODE"
113
+ def show_error(validator, keys)
114
+ return unless validator.errors
115
+ keys = [keys] unless keys.is_a?(Array)
116
+ field_name = keys.last
117
+ if validator.errors.any?
118
+ result = find_value(validator.errors, keys)
119
+ return "\#{field_name.to_s.humanize} \#{result.join(', ')}" unless result.blank?
120
+ end
121
+ end
122
+
123
+ def find_value(hash, keys)
124
+ result = hash
125
+ keys.each do |key|
126
+ if result.is_a?(Hash) && result.key?(key)
127
+ result = result[key]
128
+ elsif result.is_a?(Array)
129
+ result = result.map { |item| item.is_a?(Hash) ? item[key] : nil }.compact
130
+ result = result.first if result.length == 1 # If there's only one element in the array
131
+ else
132
+ return nil
133
+ end
134
+ end
135
+ result
136
+ end
137
+ CODE
138
+ end
139
+ end
140
+
141
+ def create_javascripts
142
+ template("javascript/controllers/form_controller.js", File.join("app/javascript/controllers/form_controller.js"))
143
+ end
144
+ end
145
+ end
@@ -0,0 +1,7 @@
1
+ class ConstraintError < StandardError
2
+ attr_accessor :validator
3
+
4
+ def initialize(validator)
5
+ self.validator = validator
6
+ end
7
+ end
@@ -0,0 +1,13 @@
1
+ module App
2
+ class Container < Dry::System::Container
3
+ register('contract_validator') { ContractValidator.new }
4
+ end
5
+ end
6
+
7
+ Import = App::Container.injector
8
+
9
+ Rails.configuration.after_initialize do
10
+ Dir[File.join(Rails.root, '*', 'lib', '*', 'infra', 'system', 'provider_source.rb')].each do |file|
11
+ require File.join(File.dirname(file), File.basename(file, File.extname(file)))
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ require 'utils/injection/controller_resolve_strategy'
2
+
3
+ Dry::AutoInject::Strategies.register('inject', Dry::AutoInject::Strategies::ControllerResolveStrategy)
@@ -0,0 +1,5 @@
1
+ require 'utils/application_struct'
2
+
3
+ DryStructGenerator::Config::GeneratorConfiguration.configuration do |config|
4
+ config.struct_class = ApplicationStruct
5
+ end
@@ -0,0 +1 @@
1
+ Rails.application.routes_reloader.paths.unshift *Dir[File.join(Rails.root, '*', 'lib', '*', 'infra', 'config', 'routes.rb')]
@@ -0,0 +1,14 @@
1
+ import { Controller } from "@hotwired/stimulus"
2
+
3
+ export default class extends Controller {
4
+ connect() {
5
+ const form = this.element;
6
+ form.addEventListener('submit', event => {
7
+ if (!form.checkValidity()) {
8
+ event.preventDefault()
9
+ event.stopPropagation()
10
+ }
11
+ form.classList.add('was-validated');
12
+ }, false)
13
+ }
14
+ }
@@ -0,0 +1,5 @@
1
+ class ApplicationService
2
+ def map_into(data, mapper, options = {})
3
+ DryObjectMapper::Mapper.call(data, mapper, options)
4
+ end
5
+ end
@@ -0,0 +1,32 @@
1
+ class ApplicationContract < Dry::Validation::Contract
2
+ attr_accessor :errors, :params, :result
3
+
4
+ def initialize(errors: {}, params: {}, result: nil)
5
+ super()
6
+ self.errors = errors
7
+ self.params = params
8
+ self.result = result
9
+ end
10
+
11
+ def self.command
12
+ DryStructGenerator::StructGenerator.new.call(self)
13
+ end
14
+
15
+ register_macro(:email_format) do
16
+ unless /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i.match?(value)
17
+ key.failure('not a valid email')
18
+ end
19
+ end
20
+
21
+ register_macro(:password_format) do
22
+ unless /^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$/i.match?(value)
23
+ key.failure('must contain 1 lower case letter, 1 upper case letter, 1 number, 1 special character and have a minimum length of 8')
24
+ end
25
+ end
26
+
27
+ def to_h
28
+ self.class.schema.rules.keys.inject({}) do |hash, key|
29
+ hash.merge({ key => self.send(key) })
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ class ApplicationReadStruct < Dry::Struct
2
+ transform_types {|type| type.optional }
3
+ end
@@ -0,0 +1,25 @@
1
+ class ApplicationStruct < Dry::Struct
2
+ transform_keys(&:to_sym)
3
+
4
+ transform_types do |type|
5
+ if type.default?
6
+ type.constructor do |value|
7
+ value.nil? ? Dry::Types::Undefined : value
8
+ end
9
+ else
10
+ type
11
+ end
12
+ end
13
+
14
+ def ==(other)
15
+ return false unless other
16
+
17
+ self.class == other.class && attributes == other.attributes
18
+ end
19
+
20
+ alias eql? ==
21
+
22
+ def hash
23
+ attributes.hash
24
+ end
25
+ end
@@ -0,0 +1,12 @@
1
+ class ContractValidator
2
+ def validate(input_hash, validator, options = {})
3
+ result = validator.call(input_hash)
4
+ validator.result = result
5
+ validator.params = result.to_h.with_indifferent_access
6
+
7
+ return validator.class.command.new(result.to_h.merge(options)) if result.success?
8
+
9
+ validator.errors = result.errors.to_h.with_indifferent_access
10
+ raise ConstraintError.new(validator)
11
+ end
12
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dry/auto_inject/dependency_map"
4
+
5
+ module Dry
6
+ module AutoInject
7
+ class Strategies
8
+ class ControllerResolveStrategy < Module
9
+ InstanceMethods = Class.new(Module)
10
+
11
+ attr_reader :container
12
+ attr_reader :dependency_map
13
+ attr_reader :instance_mod
14
+
15
+ def initialize(container, *dependency_names)
16
+ super()
17
+ @container = container
18
+ @dependency_map = DependencyMap.new(*dependency_names)
19
+ @instance_mod = InstanceMethods.new
20
+ end
21
+
22
+ # @api private
23
+ def included(klass)
24
+ define_resolvers
25
+ klass.send(:include, instance_mod)
26
+ super
27
+ end
28
+
29
+ private
30
+
31
+ def define_resolvers
32
+ instance_mod.class_exec(container, dependency_map) do |container, dependency_map|
33
+ dependency_map.to_h.each do |name, key|
34
+ define_method name do
35
+ container[key]
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ register :resolve, ControllerResolveStrategy
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,3 @@
1
+ module Types
2
+ include Dry.Types()
3
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ bin/rails generate module_generator Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,165 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DryModuleGenerator
4
+ class Generator < Rails::Generators::NamedBase
5
+ source_root File.expand_path("templates", __dir__)
6
+ namespace "dry_module"
7
+
8
+ argument :module_name, type: :string, required: false
9
+ class_option :class_name, type: :string, default: nil
10
+ class_option :attributes, type: :hash, default: {}
11
+
12
+ TYPE_TO_DRY_TYPE = {
13
+ 'array': "Types::Array",
14
+ 'boolean': "Types::Bool",
15
+ 'date': "Types::Date",
16
+ 'datetime': "Types::DateTime",
17
+ 'float': "Types::Float",
18
+ 'integer': "Types::Integer",
19
+ 'string': "Types::String",
20
+ 'time': "Types::Time"
21
+ }.freeze
22
+
23
+ TYPE_TO_FORM_FIELD = {
24
+ 'string': "text_field_tag",
25
+ 'date': "date_field_tag",
26
+ 'time': "time_field_tag",
27
+ 'datetime': "datetime_field_tag",
28
+ 'integer': "number_field_tag",
29
+ 'float': "text_field_tag",
30
+ 'boolean': "check_box_tag"
31
+ }.freeze
32
+
33
+ def initialize(args, *options)
34
+ super
35
+ self.module_name = args[0]
36
+ end
37
+
38
+ def create_app
39
+ template("app/service.rb", File.join("#{module_path}/app/#{class_name.downcase}_service.rb"))
40
+ template("app/list_dto.rb", File.join("#{module_path}/app/get_#{class_name.pluralize.downcase}_list_dto.rb"))
41
+ template("app/details_dto.rb", File.join("#{module_path}/app/get_#{class_name.downcase}_details_dto.rb"))
42
+ end
43
+
44
+ def create_domain
45
+ template("domain/model.rb", File.join("#{module_path}/domain/#{class_name.downcase}.rb"))
46
+ end
47
+
48
+ def create_infra
49
+ template("infra/system/provider_source.rb", File.join("#{module_path}/infra/system/provider_source.rb"))
50
+ @timestamp = Time.now.strftime("%Y%m%d%H%M%S")
51
+ template(
52
+ "infra/db/migrate/migration.rb",
53
+ File.join(
54
+ "#{module_path}/infra/db/migrate/#{@timestamp}_create_#{class_name.downcase.pluralize}.rb"
55
+ )
56
+ )
57
+ template("infra/config/application.rb", File.join("#{module_path}/infra/config/application.rb"))
58
+ template("infra/config/routes.rb", File.join("#{module_path}/infra/config/routes.rb"))
59
+ end
60
+
61
+ def create_ui
62
+ @action_type = "Create"
63
+ template("ui/create_validation.rb", File.join("#{module_path}/ui/create_#{class_name.downcase}_validator.rb"))
64
+ template("spec/ui/validation_test.rb",
65
+ File.join("#{module_name}/spec/ui/create_#{class_name.downcase}_validator_spec.rb"))
66
+ @action_type = "Update"
67
+ template("ui/update_validation.rb", File.join("#{module_path}/ui/update_#{class_name.downcase}_validator.rb"))
68
+ template("spec/ui/validation_test.rb",
69
+ File.join("#{module_name}/spec/ui/update_#{class_name.downcase}_validator_spec.rb"))
70
+
71
+ template("ui/controller.rb", File.join("#{module_path}/ui/#{class_name.pluralize.downcase}_controller.rb"))
72
+ end
73
+
74
+ def create_views
75
+ template("ui/views/form.rb", File.join("#{module_path}/ui/#{class_name.pluralize.downcase}/_form.html.erb"))
76
+ template("ui/views/index.rb", File.join("#{module_path}/ui/#{class_name.pluralize.downcase}/index.html.erb"))
77
+ template("ui/views/show.rb", File.join("#{module_path}/ui/#{class_name.pluralize.downcase}/show.html.erb"))
78
+ template("ui/views/new.rb", File.join("#{module_path}/ui/#{class_name.pluralize.downcase}/new.html.erb"))
79
+ template("ui/views/edit.rb", File.join("#{module_path}/ui/#{class_name.pluralize.downcase}/edit.html.erb"))
80
+ end
81
+
82
+ private
83
+
84
+ def module_path
85
+ "#{module_name}/lib/#{module_name}"
86
+ end
87
+
88
+ def class_name
89
+ options[:class_name]&.singularize&.capitalize || file_name.singularize.capitalize
90
+ end
91
+
92
+ def contract_definition
93
+ d = []
94
+ options[:attributes].each do |field_name, value|
95
+ type, necessity = value.split(":")
96
+ necessity ||= "required"
97
+ nullable = necessity == "required" ? "value" : "maybe"
98
+ definition = "#{necessity}(:#{field_name}).#{nullable}(:#{type}"
99
+ definition = necessity == "required" ? "#{definition}, :filled?)" : "#{definition})"
100
+ d << definition
101
+ end
102
+
103
+ d
104
+ end
105
+
106
+ def dto_definition
107
+ d = []
108
+ options[:attributes].each do |field_name, value|
109
+ type, necessity = value.split(":")
110
+ necessity ||= "required"
111
+ nullable = necessity == "required" ? "attribute" : "attribute?"
112
+
113
+ d << "#{nullable} :#{field_name}, #{TYPE_TO_DRY_TYPE[type.to_sym]}"
114
+ end
115
+
116
+ d
117
+ end
118
+
119
+ def contract_test_params
120
+ params = []
121
+ test_data = {
122
+ 'array': "[]",
123
+ 'boolean': "true",
124
+ 'date': "Date.today",
125
+ 'datetime': "DateTime.now",
126
+ 'float': "0.1",
127
+ 'integer': "1",
128
+ 'string': "'string'",
129
+ 'time': "Time.now"
130
+ }
131
+ options[:attributes].each do |field_name, value|
132
+ type, necessity = value.split(":")
133
+ required = necessity == "required"
134
+ params << {
135
+ field_name: field_name,
136
+ value: test_data[type.to_sym],
137
+ required: required
138
+ }
139
+ end
140
+
141
+ params
142
+ end
143
+
144
+ def migration_definition
145
+ d = []
146
+ options[:attributes].each do |field_name, value|
147
+ type = value.split(":").first
148
+ d << "t.#{type} :#{field_name}"
149
+ end
150
+ d
151
+ end
152
+
153
+ def form_attributes
154
+ d = []
155
+ options[:attributes].each do |field_name, value|
156
+ type, necessity = value.split(":")
157
+ required = necessity == "required"
158
+ d << { field_name: field_name, type: TYPE_TO_FORM_FIELD[type.to_sym], label: field_name.capitalize,
159
+ required: required }
160
+ end
161
+
162
+ d
163
+ end
164
+ end
165
+ end
@@ -0,0 +1,10 @@
1
+ <% module_namespacing do -%>
2
+ module <%= module_name.capitalize %>
3
+ module App
4
+ class Get<%= class_name %>DetailsDto < ApplicationReadStruct
5
+ attribute :id, Types::String
6
+ <%= dto_definition.join("\n ") %>
7
+ end
8
+ end
9
+ end
10
+ <% end %>
@@ -0,0 +1,10 @@
1
+ <% module_namespacing do -%>
2
+ module <%= module_name.capitalize %>
3
+ module App
4
+ class Get<%= class_name.pluralize %>ListDto < ApplicationReadStruct
5
+ attribute :id, Types::String
6
+ <%= dto_definition.join("\n ") %>
7
+ end
8
+ end
9
+ end
10
+ <% end %>
@@ -0,0 +1,37 @@
1
+ <% module_namespacing do -%>
2
+ module <%= module_name.capitalize %>
3
+ module App
4
+ class <%= class_name %>Service < ApplicationService
5
+ include Import[<%= class_name.downcase %>_repository: "<%= module_name %>.<%= class_name.downcase %>_repository"]
6
+
7
+ def create_<%= class_name.downcase %>(command)
8
+ result = ActiveRecord::Base.transaction do
9
+ <%= class_name.downcase %>_repository.create!(command.to_h.merge(id: SecureRandom.uuid))
10
+ end
11
+ end
12
+
13
+ def update_<%= class_name.downcase %>(command)
14
+ result = ActiveRecord::Base.transaction do
15
+ <%= class_name.downcase %> = <%= class_name.downcase %>_repository.find(command.id)
16
+ <%= class_name.downcase %>.update!(command.to_h)
17
+ <%= class_name.downcase %>
18
+ end
19
+ end
20
+
21
+ def delete_<%= class_name.downcase %>(id)
22
+ result = ActiveRecord::Base.transaction do
23
+ <%= class_name.downcase %>_repository.delete!(<%= class_name.downcase %>_repository.find(id))
24
+ end
25
+ end
26
+
27
+ def get_all_<%= class_name.pluralize.downcase %>
28
+ map_into(<%= class_name.downcase %>_repository.all, Get<%= class_name.pluralize %>ListDto)
29
+ end
30
+
31
+ def get_<%= class_name.downcase %>(id)
32
+ map_into(<%= class_name.downcase %>_repository.find(id), Get<%= class_name %>DetailsDto)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ <% end -%>
@@ -0,0 +1,9 @@
1
+ <% module_namespacing do -%>
2
+ module <%= module_name.capitalize %>
3
+ module Domain
4
+ class <%= class_name %> < ApplicationRecord
5
+ self.table_name = "<%= class_name.pluralize.downcase %>"
6
+ end
7
+ end
8
+ end
9
+ <% end %>
@@ -0,0 +1,5 @@
1
+ <% module_namespacing do -%>
2
+ <%= Rails.application.class %>.config.paths.add '<%= module_name %>/lib', load_path: true, autoload: true
3
+ <%= Rails.application.class %>.config.paths['db/migrate'] << '<%= module_path %>/infra/db/migrate'
4
+ <%= Rails.application.class %>.config.paths['app/views'] << '<%= module_name %>/lib'
5
+ <% end %>
@@ -0,0 +1,5 @@
1
+ <% module_namespacing do -%>
2
+ Rails.application.routes.draw do
3
+ resources :<%= class_name.pluralize.downcase %>, controller: "<%= module_name %>/ui/<%= class_name.pluralize.downcase %>"
4
+ end
5
+ <% end %>
@@ -0,0 +1,12 @@
1
+ <% module_namespacing do -%>
2
+ class Create<%= class_name.pluralize %> < ActiveRecord::Migration[<%= ActiveRecord::VERSION::MAJOR %>.<%= ActiveRecord::VERSION::MINOR %>]
3
+ def change
4
+ create_table :<%= class_name.pluralize.downcase %>, id: false do |t|
5
+ t.string :id, limit: 36, primary_key: true
6
+ <%= migration_definition.join("\n ") %>
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+ end
12
+ <% end %>
@@ -0,0 +1,11 @@
1
+ <% module_namespacing do -%>
2
+ Dry::System.register_provider_source(:<%= module_name %>, group: :<%= module_name %>) do
3
+ prepare do
4
+ register("<%= module_name %>.<%= class_name.downcase %>_repository") { <%= module_name.capitalize %>::Domain::<%= class_name %> }
5
+ register("<%= module_name %>.<%= class_name.downcase %>_service") { <%= module_name.capitalize %>::App::<%= class_name %>Service.new }
6
+ end
7
+ end
8
+
9
+ App::Container.register_provider(:<%= module_name %>, from: :<%= module_name %>)
10
+ App::Container.start(:<%= module_name %>)
11
+ <% end %>
@@ -0,0 +1,25 @@
1
+ <% module_namespacing do -%>
2
+ require 'rails_helper'
3
+
4
+ RSpec.describe <%= module_name.capitalize %>::Ui::<%= @action_type %><%= class_name %>Validator, type: :unit do
5
+ describe '#.call(params)' do
6
+ let(:params) do
7
+ { <% contract_test_params.each do |param| %>
8
+ <%= param[:field_name] %>: <%= param[:value] %>,<% end %>
9
+ }
10
+ end
11
+
12
+ context 'when all of the required parameters are present' do
13
+ it 'should return success true' do
14
+ expect(described_class.new.call(params).success?).to be_truthy
15
+ end
16
+ end
17
+
18
+ context 'when a required parameter is missing' do <% contract_test_params.filter {|it| it[:required] == true }.each do |param| %>
19
+ it 'should raise an error when <%= param[:field_name] %> is missing' do
20
+ expect(described_class.new.call(params.except(:<%= param[:field_name] %>)).success?).to be_falsey
21
+ end<% end %>
22
+ end
23
+ end
24
+ end
25
+ <% end %>
@@ -0,0 +1,53 @@
1
+ <% module_namespacing do -%>
2
+ <%
3
+ controller_name = "#{class_name.pluralize}Controller"
4
+ service_name = "#{class_name.singularize.downcase}_service"
5
+ pluralized_variable_name = class_name.pluralize.downcase
6
+ singularize_variable_name = class_name.singularize.downcase
7
+ view_path_name = class_name.pluralize.downcase
8
+ %>module <%= module_name.capitalize %>
9
+ module Ui
10
+ class <%= controller_name %> < ApplicationController
11
+ include Import.inject[<%= service_name %>: "<%= module_name %>.<%= service_name %>"]
12
+
13
+ def index
14
+ @<%= pluralized_variable_name %> = <%= service_name %>.get_all_<%= pluralized_variable_name %>
15
+ end
16
+
17
+ def new
18
+ @form = Create<%= class_name.singularize %>Validator.new
19
+ end
20
+
21
+ def create
22
+ <%= service_name %>.create_<%= singularize_variable_name %>(validator.validate(<%= singularize_variable_name %>_params, Create<%= class_name.singularize %>Validator.new))
23
+ redirect_to <%= view_path_name %>_path, notice: "<%= class_name %> was successfully created!"
24
+ end
25
+
26
+ def show
27
+ @<%= singularize_variable_name %> = <%= service_name %>.get_<%= singularize_variable_name %>(params[:id])
28
+ end
29
+
30
+ def edit
31
+ @<%= singularize_variable_name %> = <%= service_name %>.get_<%= singularize_variable_name %>(params[:id])
32
+ @form = Update<%= class_name.singularize %>Validator.new(params: { <% options[:attributes].each do |field_name, value| %><%= field_name %>: @<%= singularize_variable_name %>.<%= field_name %>, <% end %> })
33
+ end
34
+
35
+ def update
36
+ <%= service_name %>.update_<%= singularize_variable_name %>(validator.validate(<%= singularize_variable_name %>_params, Update<%= class_name.singularize %>Validator.new, { id: params[:id] }))
37
+ redirect_to <%= view_path_name %>_path, notice: "<%= class_name %> was successfully updated!"
38
+ end
39
+
40
+ def destroy
41
+ <%= service_name %>.delete_<%= singularize_variable_name %>(params[:id])
42
+ redirect_to <%= view_path_name %>_path, notice: "<%= class_name %> was successfully deleted!"
43
+ end
44
+
45
+ private
46
+
47
+ def <%= singularize_variable_name %>_params
48
+ params.require(:<%= singularize_variable_name %>).to_unsafe_h
49
+ end
50
+ end
51
+ end
52
+ end
53
+ <% end %>
@@ -0,0 +1,11 @@
1
+ <% module_namespacing do -%>
2
+ module <%= module_name.capitalize %>
3
+ module Ui
4
+ class Create<%= class_name %>Validator < ApplicationContract
5
+ params do
6
+ <%= contract_definition.join("\n ") %>
7
+ end
8
+ end
9
+ end
10
+ end
11
+ <% end %>
@@ -0,0 +1,15 @@
1
+ <% module_namespacing do -%>
2
+ module <%= module_name.capitalize %>
3
+ module Ui
4
+ class Update<%= class_name %>Validator < ApplicationContract
5
+ params do
6
+ <%= contract_definition.join("\n ") %>
7
+ end
8
+
9
+ def self.command
10
+ ::StructGenerator.call(self, { id: { required: true, type: 'string', null: false } })
11
+ end
12
+ end
13
+ end
14
+ end
15
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <% module_namespacing do -%>
2
+ <div class="row mb-3 mt-3">
3
+ <span class="fs-5 fw-semibold">Edit <%= class_name %></span>
4
+ </div>
5
+ <%%= render 'form', url: <%= class_name.downcase %>_path(id: params[:id]), method: :patch, button_text: 'Update' %>
6
+ <% end %>
@@ -0,0 +1,12 @@
1
+ <% module_namespacing do -%>
2
+ <%%= form_tag(url, method: method, id: 'form', novalidate: true, "data-controller": 'form') do %>
3
+ <% form_attributes.each do |attribute| %><div class="form-floating mb-3">
4
+ <%%= <%= attribute[:type] %> '<%= class_name.downcase %>[<%= attribute[:field_name] %>]', @form.params.dig(:<%= attribute[:field_name] %>), class: 'form-control', placeholder: '<%= attribute[:field_name].capitalize.humanize %>', required: <%= attribute[:required] %> %>
5
+ <%%= label_tag '<%= class_name.downcase %>[<%= attribute[:field_name] %>]', '<%= attribute[:label].humanize %>' %>
6
+ <p class="text-danger errors"><%%= show_error(@form, :<%= attribute[:field_name] %>) %></p>
7
+ </div>
8
+ <% end %>
9
+ <%%= button_tag button_text, class: 'btn btn-primary' %>
10
+ <%%= link_to "Back", <%= class_name.pluralize.downcase %>_path, class: "btn btn-danger" %>
11
+ <%% end %>
12
+ <% end %>
@@ -0,0 +1,36 @@
1
+ <% module_namespacing do -%>
2
+ <div class="row align-items-end mb-3 mt-3">
3
+ <div class="col">
4
+ <span class="fs-5 fw-semibold"><%= class_name.pluralize %></span>
5
+ </div>
6
+
7
+ <div class="col text-end">
8
+ <%%= link_to 'Add <%= class_name.singularize %>', new_<%= class_name.downcase %>_path, class: "btn btn-primary btn-sm" %>
9
+ </div>
10
+ </div>
11
+
12
+ <div class="table-responsive">
13
+ <table class="table text-nowrap mb-0">
14
+ <thead class="bg-light">
15
+ <tr><% options[:attributes].each do |field_name, _| %>
16
+ <th scope="col" class="fw-semibold p-3"><%= field_name.capitalize.humanize %></th><% end %>
17
+ <th scope="col" class="fw-semibold p-3">Actions</th>
18
+ </tr>
19
+ </thead>
20
+
21
+ <tbody class="bg-white">
22
+ <%% @<%= class_name.pluralize.downcase %>.each do |<%= class_name.downcase %>| %>
23
+ <tr><% options[:attributes].each do |field_name, _| %>
24
+ <td class="p-3"> <%%= <%= class_name.downcase %>.<%= field_name %> || '/' %> </td><% end %>
25
+ <td class="p-3">
26
+ <%%= link_to "Show", <%= class_name.downcase %>_path(id: <%= class_name.downcase %>.id), class: "me-2 text-decoration-none" %>
27
+ <%%= link_to "Edit", edit_<%= class_name.downcase %>_path(id: <%= class_name.downcase %>.id), class: "me-2 text-decoration-none" %>
28
+ <%%= link_to "Destroy", <%= class_name.downcase %>_path(id: <%= class_name.downcase %>.id), data: { "turbo-method": :delete }, class: "link-danger me-2 text-decoration-none" %>
29
+ </td>
30
+ </tr>
31
+ <%% end %>
32
+ </tbody>
33
+ </table>
34
+ </div>
35
+ <% end %>
36
+
@@ -0,0 +1,7 @@
1
+ <% module_namespacing do -%>
2
+ <div class="row mb-3 mt-3">
3
+ <span class="fs-5 fw-semibold">Add <%= class_name %></span>
4
+ </div>
5
+ <%%= render 'form', url: <%= class_name.pluralize.downcase %>_path, method: :post, button_text: 'Save' %>
6
+ <% end %>
7
+
@@ -0,0 +1,16 @@
1
+ <% module_namespacing do -%>
2
+ <div class="row mb-3 mt-3">
3
+ <span class="fs-5 fw-semibold"><%= class_name %> Details </span>
4
+ </div>
5
+
6
+ <div id="<%%= @<%= class_name.downcase %>.id %>" class="row">
7
+ <% options[:attributes].each do |field_name, _| %><div class="col-6">
8
+ <p class="fw-semibold"><%= field_name.capitalize.humanize %></p>
9
+ </div>
10
+ <div class="col-6">
11
+ <p class="text-secondary"><%%= @<%= class_name.downcase %>.<%= field_name %> || '/' %></p>
12
+ </div>
13
+ <hr style="opacity: 0.10"><% end %>
14
+ </div>
15
+ <%%= link_to "Back to <%= class_name.pluralize.downcase %>", <%= class_name.pluralize.downcase %>_path, class: "btn btn-danger" %>
16
+ <% end %>
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails"
4
+
5
+ module DryModuleGenerator
6
+ class Railtie < Rails::Railtie
7
+ config.generators do |generators|
8
+ generators.templates.unshift File.expand_path("lib/dry_module_generator/module", __dir__)
9
+ generators.templates.unshift File.expand_path("lib/dry_module_generator/install", __dir__)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DryModuleGenerator
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "dry_module_generator/version"
4
+ require "rails/generators"
5
+ require_relative "dry_module_generator/install/installer"
6
+ require_relative "dry_module_generator/module/generator"
7
+
8
+ module DryModuleGenerator
9
+ class Error < StandardError; end
10
+ # Your code goes here...
11
+ end
@@ -0,0 +1,4 @@
1
+ module DryModuleGenerator
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dry_module_generator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jane-Terziev
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-01-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
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
+ A custom generator for creating features as modules using the dry.rb gems. The module registers a
29
+ dry system provider, adds routes, view and migrations paths to the application configuration and registers the models
30
+ and services for dependency injection.
31
+ email:
32
+ - janeterziev@gmail.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - ".rspec"
38
+ - ".rubocop.yml"
39
+ - CHANGELOG.md
40
+ - CODE_OF_CONDUCT.md
41
+ - LICENSE.txt
42
+ - README.md
43
+ - Rakefile
44
+ - lib/dry_module_generator.rb
45
+ - lib/dry_module_generator/install/USAGE
46
+ - lib/dry_module_generator/install/installer.rb
47
+ - lib/dry_module_generator/install/templates/errors/constraint_error.rb.tt
48
+ - lib/dry_module_generator/install/templates/initializers/container.rb.tt
49
+ - lib/dry_module_generator/install/templates/initializers/dependency_injection.rb.tt
50
+ - lib/dry_module_generator/install/templates/initializers/dry_struct_generator.rb.tt
51
+ - lib/dry_module_generator/install/templates/initializers/routes.rb.tt
52
+ - lib/dry_module_generator/install/templates/javascript/controllers/form_controller.js.tt
53
+ - lib/dry_module_generator/install/templates/services/application_service.rb.tt
54
+ - lib/dry_module_generator/install/templates/utils/application_contract.rb.tt
55
+ - lib/dry_module_generator/install/templates/utils/application_read_struct.rb.tt
56
+ - lib/dry_module_generator/install/templates/utils/application_struct.rb.tt
57
+ - lib/dry_module_generator/install/templates/utils/contract_validator.rb.tt
58
+ - lib/dry_module_generator/install/templates/utils/injection/controller_resolve_strategy.rb.tt
59
+ - lib/dry_module_generator/install/templates/utils/types.rb.tt
60
+ - lib/dry_module_generator/module/USAGE
61
+ - lib/dry_module_generator/module/generator.rb
62
+ - lib/dry_module_generator/module/templates/app/details_dto.rb.tt
63
+ - lib/dry_module_generator/module/templates/app/list_dto.rb.tt
64
+ - lib/dry_module_generator/module/templates/app/service.rb.tt
65
+ - lib/dry_module_generator/module/templates/domain/model.rb.tt
66
+ - lib/dry_module_generator/module/templates/infra/config/application.rb.tt
67
+ - lib/dry_module_generator/module/templates/infra/config/routes.rb.tt
68
+ - lib/dry_module_generator/module/templates/infra/db/migrate/migration.rb.tt
69
+ - lib/dry_module_generator/module/templates/infra/system/provider_source.rb.tt
70
+ - lib/dry_module_generator/module/templates/spec/ui/validation_test.rb.tt
71
+ - lib/dry_module_generator/module/templates/ui/controller.rb.tt
72
+ - lib/dry_module_generator/module/templates/ui/create_validation.rb.tt
73
+ - lib/dry_module_generator/module/templates/ui/update_validation.rb.tt
74
+ - lib/dry_module_generator/module/templates/ui/views/edit.rb.tt
75
+ - lib/dry_module_generator/module/templates/ui/views/form.rb.tt
76
+ - lib/dry_module_generator/module/templates/ui/views/index.rb.tt
77
+ - lib/dry_module_generator/module/templates/ui/views/new.rb.tt
78
+ - lib/dry_module_generator/module/templates/ui/views/show.rb.tt
79
+ - lib/dry_module_generator/railtie.rb
80
+ - lib/dry_module_generator/version.rb
81
+ - sig/dry_module_generator.rbs
82
+ homepage: https://github.com/Jane-Terziev/dry_module_generator
83
+ licenses:
84
+ - MIT
85
+ metadata:
86
+ allowed_push_host: https://rubygems.org
87
+ homepage_uri: https://github.com/Jane-Terziev/dry_module_generator
88
+ source_code_uri: https://github.com/Jane-Terziev/dry_module_generator
89
+ changelog_uri: https://github.com/Jane-Terziev/dry_module_generator
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: 2.6.0
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubygems_version: 3.4.10
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: A custom generator for creating features as modules using the dry.rb gems
109
+ test_files: []