dry-operation_generators 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +24 -0
- data/.rubocop_todo.yml +44 -0
- data/.tool-versions +1 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/LICENSE.txt +21 -0
- data/PRIVATE_NOTES.md +18 -0
- data/README.md +156 -0
- data/Rakefile +14 -0
- data/config/initializers/dry_schema.rb +19 -0
- data/lib/dry-operations.rb +3 -0
- data/lib/operations/create_generator.rb +62 -0
- data/lib/operations/generators/action/templates/action.rb.erb +50 -0
- data/lib/operations/generators/action_generator.rb +17 -0
- data/lib/operations/generators/contract/templates/base/contract.rb.erb +14 -0
- data/lib/operations/generators/contract/templates/contract.rb.erb +19 -0
- data/lib/operations/generators/contract_generator.rb +22 -0
- data/lib/operations/generators/install/templates/application_contract.rb.tt +9 -0
- data/lib/operations/generators/install/templates/application_schema.rb.tt +4 -0
- data/lib/operations/generators/install/templates/dry_schema.rb.tt +19 -0
- data/lib/operations/generators/install/templates/dry_types.rb.tt +5 -0
- data/lib/operations/generators/install_generator.rb +18 -0
- data/lib/operations/generators/operation/templates/operation.rb.erb +26 -0
- data/lib/operations/generators/operation_generator.rb +21 -0
- data/lib/operations/generators/register/templates/register.rb.erb +27 -0
- data/lib/operations/generators/register_generator.rb +17 -0
- data/lib/operations/generators/repository/templates/repository.rb.erb +29 -0
- data/lib/operations/generators/repository_generator.rb +17 -0
- data/lib/operations/generators/scaffold_generator.rb +40 -0
- data/lib/operations/generators/schema/templates/base/schema.rb.erb +12 -0
- data/lib/operations/generators/schema/templates/schema.rb.erb +19 -0
- data/lib/operations/generators/schema_generator.rb +22 -0
- data/lib/operations/generators/setup/templates/generators.rb.tt +19 -0
- data/lib/operations/generators/setup_generator.rb +13 -0
- data/lib/operations/generators/validation/templates/validation.rb.erb +23 -0
- data/lib/operations/generators/validation_generator.rb +17 -0
- data/lib/operations/templates/template_generator.rb.erb +23 -0
- data/lib/operations/templates/template_generator_spec.rb.erb +54 -0
- data/lib/operations/version.rb +5 -0
- data/lib/operations.rb +15 -0
- data/operation_generators.gemspec +35 -0
- data/sig/operations.rbs +4 -0
- metadata +129 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fa2ca41a11677ba216e23c6d2dfc745ef36aac45c4ac31706e7292f97d877578
|
4
|
+
data.tar.gz: 25cebb74e7ca7b6f5597beb459e855bda57a2b8ec7c24d2b129d98e0ea6c71e0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 14d1177d692a0b6c95bf7f9dd7fe95503bf403a7afafd799418107e3f9687ba0d447951a23ba6b1a1fe721be999d2ee0444baa4151a6163d521e5d1cc358e8fb
|
7
|
+
data.tar.gz: 2e8e4cdd4f0463cbf5a42a4ba2aa7af1798017db0fb5668fd68e5e6c3998b5156d40355614b18c31db8053c421d08f89bf55af80dbdf57f1afcc1ee4d35a7d07
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
2
|
+
|
3
|
+
require:
|
4
|
+
- rubocop-performance
|
5
|
+
- rubocop-rake
|
6
|
+
- rubocop-rspec
|
7
|
+
|
8
|
+
AllCops:
|
9
|
+
TargetRubyVersion: 3.3.0
|
10
|
+
NewCops: enable
|
11
|
+
|
12
|
+
Style/StringLiterals:
|
13
|
+
Enabled: true
|
14
|
+
EnforcedStyle: double_quotes
|
15
|
+
|
16
|
+
Style/StringLiteralsInInterpolation:
|
17
|
+
Enabled: true
|
18
|
+
EnforcedStyle: double_quotes
|
19
|
+
|
20
|
+
Style/Documentation:
|
21
|
+
Enabled: false
|
22
|
+
|
23
|
+
Lint/SuppressedException:
|
24
|
+
Enabled: false
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2024-03-15 13:30:02 UTC using RuboCop version 1.60.2.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 1
|
10
|
+
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
|
11
|
+
Metrics/AbcSize:
|
12
|
+
Max: 44
|
13
|
+
|
14
|
+
# Offense count: 2
|
15
|
+
# Configuration parameters: AllowedMethods, AllowedPatterns.
|
16
|
+
Metrics/CyclomaticComplexity:
|
17
|
+
Max: 11
|
18
|
+
|
19
|
+
# Offense count: 1
|
20
|
+
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
|
21
|
+
Metrics/MethodLength:
|
22
|
+
Max: 16
|
23
|
+
|
24
|
+
# Offense count: 1
|
25
|
+
# Configuration parameters: AllowedMethods, AllowedPatterns.
|
26
|
+
Metrics/PerceivedComplexity:
|
27
|
+
Max: 11
|
28
|
+
|
29
|
+
# Offense count: 1
|
30
|
+
# Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, CheckDefinitionPathHierarchyRoots, Regex, IgnoreExecutableScripts, AllowedAcronyms.
|
31
|
+
# CheckDefinitionPathHierarchyRoots: lib, spec, test, src
|
32
|
+
# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
|
33
|
+
Naming/FileName:
|
34
|
+
Exclude:
|
35
|
+
- 'lib/dry-operations.rb'
|
36
|
+
|
37
|
+
# Offense count: 9
|
38
|
+
# Configuration parameters: CountAsOne.
|
39
|
+
RSpec/ExampleLength:
|
40
|
+
Max: 26
|
41
|
+
|
42
|
+
# Offense count: 3
|
43
|
+
RSpec/MultipleExpectations:
|
44
|
+
Max: 3
|
data/.tool-versions
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby 3.3.0
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -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 joel.azemar@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 Joel Azemar
|
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/PRIVATE_NOTES.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# Build Gem
|
2
|
+
|
3
|
+
> gem build
|
4
|
+
|
5
|
+
# Publish Gem
|
6
|
+
|
7
|
+
> gem push uuid_v7-0.1.0.gem
|
8
|
+
|
9
|
+
# Tag
|
10
|
+
|
11
|
+
> mv -v *.gem gems/
|
12
|
+
|
13
|
+
> git add . && git stash save "Initial Release"
|
14
|
+
|
15
|
+
> git tag -a v0.1.0 main -m "Version 0.1.0"
|
16
|
+
|
17
|
+
> git push --tags
|
18
|
+
|
data/README.md
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
# Operation Generators
|
2
|
+
|
3
|
+
Operation Generators is a utility library designed to streamline and expedite the development process within the Dry RB ecosystem by automating the creation of a comprehensive set of files required for new Business Logic actions.
|
4
|
+
|
5
|
+
Reducing manual boilerplate code and enforcing a unified code structure enhances productivity and consistency while minimizing the potential for errors.
|
6
|
+
|
7
|
+
The following files are generated for the action `Create` of the resource `User`:
|
8
|
+
|
9
|
+
```shell
|
10
|
+
components/identity/operations/users/create/
|
11
|
+
├── action.rb
|
12
|
+
├── contract.rb
|
13
|
+
├── operation.rb
|
14
|
+
├── register.rb
|
15
|
+
├── repository.rb
|
16
|
+
├── schema.rb
|
17
|
+
└── validation.rb
|
18
|
+
```
|
19
|
+
|
20
|
+
For those files, we need their test counterpart.
|
21
|
+
|
22
|
+
```shell
|
23
|
+
test/components/identity/operations/users/create/
|
24
|
+
├── acction_test.rb
|
25
|
+
├── contract_test.rb
|
26
|
+
├── operation_test.rb
|
27
|
+
├── register_test.rb
|
28
|
+
├── repository_test.rb
|
29
|
+
├── schema_test.rb
|
30
|
+
└── validation_test.rb
|
31
|
+
```
|
32
|
+
|
33
|
+
Please check out [TestUnit Generators](https://github.com/orgs/joel/dry-operation_generators-test_unit)
|
34
|
+
|
35
|
+
Concerning the volume on file needed, the generator will help to reduce the burden and lower the boilerplate of adding a new action. On top of that, it helps reduce typos and make code more unified.
|
36
|
+
|
37
|
+
It aims to speed up the development.
|
38
|
+
|
39
|
+
## Installation
|
40
|
+
|
41
|
+
Install the gem and add to the application's Gemfile by executing:
|
42
|
+
|
43
|
+
$ bundle add operation_generators
|
44
|
+
|
45
|
+
If Bundler is not being used to manage dependencies, install the gem by executing:
|
46
|
+
|
47
|
+
$ gem install operation_generators
|
48
|
+
|
49
|
+
NOTE: The gem needs to be required as `operations`
|
50
|
+
|
51
|
+
$ gem "operation_generators", require: "operations"
|
52
|
+
|
53
|
+
Otherwise, you can require "operations" on your code.
|
54
|
+
|
55
|
+
## Usage
|
56
|
+
|
57
|
+
Once installed, you can print out the Rails Generators Help:
|
58
|
+
|
59
|
+
```shell
|
60
|
+
rails generate --help
|
61
|
+
```
|
62
|
+
|
63
|
+
You should see
|
64
|
+
|
65
|
+
```shell
|
66
|
+
Operations:
|
67
|
+
operations:setup
|
68
|
+
```
|
69
|
+
|
70
|
+
You will need to run the Setup to make the generators available in the Host Application.
|
71
|
+
|
72
|
+
```shell
|
73
|
+
rails generate operations:setup --force
|
74
|
+
# => initializer operation_generators.rb
|
75
|
+
```
|
76
|
+
|
77
|
+
Now the Generators should appear:
|
78
|
+
|
79
|
+
```shell
|
80
|
+
Operations:
|
81
|
+
operations:action
|
82
|
+
operations:contract
|
83
|
+
operations:operation
|
84
|
+
operations:register
|
85
|
+
operations:repository
|
86
|
+
operations:schema
|
87
|
+
operations:validation
|
88
|
+
```
|
89
|
+
|
90
|
+
You can print the help for any generator:
|
91
|
+
|
92
|
+
```shell
|
93
|
+
rails generate operations:<generator name> --help
|
94
|
+
```
|
95
|
+
|
96
|
+
And the special ones:
|
97
|
+
|
98
|
+
```shell
|
99
|
+
Operations:
|
100
|
+
operations:install
|
101
|
+
operations:scaffold
|
102
|
+
operations:setup
|
103
|
+
```
|
104
|
+
|
105
|
+
### Install Generator
|
106
|
+
|
107
|
+
The `install` generator needs to be run to install the shared files, such as `app/operations/application_contract.rb` of `app/operations/application_schema.rb` that generator might merge into `setup` in the future. Still, I feel it serves a different purpose, and I like to run it separately.
|
108
|
+
|
109
|
+
### Scaffold Generator
|
110
|
+
|
111
|
+
The `scaffold` generator calls all the generators at once.
|
112
|
+
|
113
|
+
```shell
|
114
|
+
rails generate operations:scaffold user create firstname:string{optional} --component identity/users --force
|
115
|
+
create components/identity/operations/users/create/action.rb
|
116
|
+
invoke test_unit
|
117
|
+
create test/components/identity/operations/users/create/contract_test.rb
|
118
|
+
create components/identity/operations/users/base/contract.rb
|
119
|
+
create components/identity/operations/users/create/contract.rb
|
120
|
+
invoke test_unit
|
121
|
+
create test/components/identity/operations/users/create/schema_test.rb
|
122
|
+
create components/identity/operations/users/base/schema.rb
|
123
|
+
create components/identity/operations/users/create/schema.rb
|
124
|
+
create components/identity/operations/users/create/validation.rb
|
125
|
+
create components/identity/operations/users/create/repository.rb
|
126
|
+
create components/identity/operations/users/create/register.rb
|
127
|
+
invoke test_unit
|
128
|
+
create test/components/identity/operations/users/create/operation_test.rb
|
129
|
+
create components/identity/operations/users/create/operation.rb
|
130
|
+
```
|
131
|
+
|
132
|
+
## Development
|
133
|
+
|
134
|
+
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.
|
135
|
+
|
136
|
+
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).
|
137
|
+
|
138
|
+
## Contributing
|
139
|
+
|
140
|
+
There is a generator of generators you can use to quickly add a new generator:
|
141
|
+
|
142
|
+
```shell
|
143
|
+
./bin/generator <generator name> --no-dry_run
|
144
|
+
```
|
145
|
+
|
146
|
+
That provides the skeleton for the new generator. Note that the test suite should still run after the generated files.
|
147
|
+
|
148
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/orgs/joel/dry-operation_generators. 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/joel/dry-operation_generators/blob/main/CODE_OF_CONDUCT.md).
|
149
|
+
|
150
|
+
## License
|
151
|
+
|
152
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
153
|
+
|
154
|
+
## Code of Conduct
|
155
|
+
|
156
|
+
Everyone interacting in the Isms project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/joel/dry-operation_generators/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
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(:rubocop) do |task|
|
11
|
+
task.options = ["-A"] # auto_correct
|
12
|
+
end
|
13
|
+
|
14
|
+
task default: %i[spec rubocop]
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "dry/schema"
|
4
|
+
|
5
|
+
# Could be acheived with:
|
6
|
+
|
7
|
+
# Dry::Schema.load_extensions(:info)
|
8
|
+
|
9
|
+
# UserSchema.info.keys
|
10
|
+
|
11
|
+
# NOTE: The info data structure is not stable yet and may change before 2.0.0 depending on the user feedback. ^
|
12
|
+
|
13
|
+
module ExtractKeysFromSchema
|
14
|
+
def key_list
|
15
|
+
key_map.keys.map { |key| key.name.to_sym }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
Dry::Schema.Params.class.include(ExtractKeysFromSchema)
|
@@ -0,0 +1,62 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
begin
|
5
|
+
require "thor/group"
|
6
|
+
rescue LoadError
|
7
|
+
puts "Thor is not available.\nIf you ran this command from a git checkout " \
|
8
|
+
"of Rails, please make sure thor is installed,\nand run this command " \
|
9
|
+
"as `ruby #{$PROGRAM_NAME} #{(ARGV | ["--dev"]).join(" ")}`"
|
10
|
+
exit
|
11
|
+
end
|
12
|
+
|
13
|
+
require "active_support/inflector"
|
14
|
+
|
15
|
+
module Operations
|
16
|
+
class CreateGenerator < Thor::Group
|
17
|
+
include Thor::Actions
|
18
|
+
|
19
|
+
class << self
|
20
|
+
def exit_on_failure?
|
21
|
+
true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "Create a new Generator (Generator of generators)"
|
26
|
+
|
27
|
+
source_root File.expand_path(".", __dir__)
|
28
|
+
|
29
|
+
class_option :force, type: :boolean, default: false
|
30
|
+
class_option :hook_for_test_framework, type: :boolean, default: true
|
31
|
+
class_option :dry_run, type: :boolean, default: true
|
32
|
+
|
33
|
+
argument :name, type: :string, required: true, desc: "Name of the generator"
|
34
|
+
|
35
|
+
def plural_name
|
36
|
+
name.pluralize
|
37
|
+
end
|
38
|
+
|
39
|
+
def singular_name
|
40
|
+
name.singularize
|
41
|
+
end
|
42
|
+
|
43
|
+
def class_name
|
44
|
+
singular_name.capitalize
|
45
|
+
end
|
46
|
+
|
47
|
+
def copy_generator_files
|
48
|
+
return if options[:dry_run]
|
49
|
+
|
50
|
+
template "templates/template_generator.rb.erb", "lib/operations/generators/#{name}_generator.rb"
|
51
|
+
template "templates/template_generator_spec.rb.erb",
|
52
|
+
"spec/operations/generators/#{name}_generator_spec.rb"
|
53
|
+
|
54
|
+
create_file "lib/operations/generators/#{name}/templates/#{name}.rb.erb" do
|
55
|
+
"This is #{name}.rb.erb"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# ./bin/generator <generator name> --no-dry_run
|
62
|
+
Operations::CreateGenerator.start(ARGV)
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "dry/transaction/operation"
|
4
|
+
|
5
|
+
module <%= class_name.pluralize %>
|
6
|
+
module <%= verb.capitalize %>
|
7
|
+
class Action
|
8
|
+
|
9
|
+
include Dry::Transaction::Operation
|
10
|
+
|
11
|
+
def call(params)
|
12
|
+
instance, input = params.values_at(:instance, :input)
|
13
|
+
<%- case verb -%>
|
14
|
+
<%- when /create|update/ -%>
|
15
|
+
<%- if @reference_parsed_fields.empty? %>
|
16
|
+
attributes = input.dup # use except or slice to filter out unwanted attributes
|
17
|
+
<%- else %>
|
18
|
+
attributes = input.dup.except(
|
19
|
+
:id, :created_at, :updated_at, <%= @reference_parsed_fields.map { |f| ":#{f.foreign_key}" }.join(", ") %>
|
20
|
+
) # use except or slice to filter out unwanted attributes
|
21
|
+
<%- end %>
|
22
|
+
# Recommended to use slice to filter out unwanted attributes
|
23
|
+
# attributes = input.dup.slice(
|
24
|
+
# TODO: whitelisted attributes here
|
25
|
+
# )
|
26
|
+
|
27
|
+
instance.assign_attributes(attributes)
|
28
|
+
|
29
|
+
<%- @reference_parsed_fields.each do |field| -%>
|
30
|
+
instance.<%= field.name %> = <%= field.class_name %>.find_by(<%= Operations.configuration.primary_key_name %>: input[:<%= field.foreign_key %>])
|
31
|
+
<%- end -%>
|
32
|
+
<%- end -%>
|
33
|
+
|
34
|
+
# Here comes the Busniness Logic
|
35
|
+
|
36
|
+
<%- case verb -%>
|
37
|
+
<%- when "destroy" -%>
|
38
|
+
if instance.destroy
|
39
|
+
<%- else %>
|
40
|
+
if instance.save
|
41
|
+
<%- end -%>
|
42
|
+
Success(instance)
|
43
|
+
else
|
44
|
+
Failure(instance)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Operations
|
4
|
+
module Generators
|
5
|
+
class ActionGenerator < Rails::Generators::NamedBase
|
6
|
+
include Base::Generators::BaseGenerator
|
7
|
+
|
8
|
+
source_root File.expand_path("action/templates", __dir__)
|
9
|
+
|
10
|
+
def generate_files
|
11
|
+
super
|
12
|
+
|
13
|
+
template "action.rb.erb", "#{root_file_path}/operations/#{plural_name}/#{verb}/action.rb"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# The domain validation logic is in the contract, not the schema.
|
4
|
+
|
5
|
+
module <%= class_name.pluralize %>
|
6
|
+
module Base
|
7
|
+
class Contract < ApplicationContract
|
8
|
+
|
9
|
+
# Add common rules here
|
10
|
+
# rule(:email).validate(:email_format)
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module <%= class_name.pluralize %>
|
4
|
+
module <%= verb.capitalize %>
|
5
|
+
class Contract < Dry::Validation::Contract
|
6
|
+
|
7
|
+
params(Base::Schema, Schema)
|
8
|
+
|
9
|
+
# Add domain validation rules here
|
10
|
+
|
11
|
+
<%- @reference_parsed_fields.each do |field| -%>
|
12
|
+
rule(:<%= field.foreign_key %>) do
|
13
|
+
key.failure("must exist") if <%= field.class_name %>.where(<%= Operations.configuration.primary_key_name %>: value).none?
|
14
|
+
end
|
15
|
+
<%- end -%>
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Operations
|
4
|
+
module Generators
|
5
|
+
class ContractGenerator < Rails::Generators::NamedBase
|
6
|
+
include Base::Generators::BaseGenerator
|
7
|
+
|
8
|
+
desc "Generates contract for operation"
|
9
|
+
|
10
|
+
hook_for :test_framework, as: "operations:contract"
|
11
|
+
|
12
|
+
source_root File.expand_path("contract/templates", __dir__)
|
13
|
+
|
14
|
+
def generate_files
|
15
|
+
super
|
16
|
+
|
17
|
+
template "base/contract.rb.erb", "#{root_file_path}/operations/#{plural_name}/base/contract.rb"
|
18
|
+
template "contract.rb.erb", "#{root_file_path}/operations/#{plural_name}/#{verb}/contract.rb"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class ApplicationContract < Dry::Validation::Contract
|
4
|
+
register_macro(:email_format) do
|
5
|
+
next unless value
|
6
|
+
|
7
|
+
key.failure("not a valid email format") unless /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i.match?(value)
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "dry/schema"
|
4
|
+
|
5
|
+
# Could be acheived with:
|
6
|
+
|
7
|
+
# Dry::Schema.load_extensions(:info)
|
8
|
+
|
9
|
+
# UserSchema.info.keys
|
10
|
+
|
11
|
+
# NOTE: The info data structure is not stable yet and may change before 2.0.0 depending on the user feedback. ^
|
12
|
+
|
13
|
+
module ExtractKeysFromSchema
|
14
|
+
def key_list
|
15
|
+
key_map.keys.map { |key| key.name.to_sym }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
Dry::Schema.Params.class.include(ExtractKeysFromSchema)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Operations
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < ::Rails::Generators::Base
|
6
|
+
source_root File.expand_path("install/templates", __dir__)
|
7
|
+
|
8
|
+
desc "This generator installs the operations setup."
|
9
|
+
|
10
|
+
def copy_setup_files
|
11
|
+
copy_file "application_contract.rb.tt", "app/operations/application_contract.rb"
|
12
|
+
copy_file "application_schema.rb.tt", "app/operations/application_schema.rb"
|
13
|
+
copy_file "dry_schema.rb.tt", "config/initializers/dry_schema.rb"
|
14
|
+
copy_file "dry_types.rb.tt", "config/initializers/dry_types.rb"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "dry/transaction/operation"
|
4
|
+
|
5
|
+
module <%= class_name.pluralize %>
|
6
|
+
module <%= verb.capitalize %>
|
7
|
+
class Operation
|
8
|
+
|
9
|
+
include Dry::Transaction(container: Register)
|
10
|
+
|
11
|
+
<%- case verb -%>
|
12
|
+
<%- when /create|update/ -%>
|
13
|
+
step :validate_inputs, with: "<%= plural_name %>.<%= verb %>.validation"
|
14
|
+
<%- end -%>
|
15
|
+
<%- case verb -%>
|
16
|
+
<%- when "create" -%>
|
17
|
+
step :initialize_record, with: "<%= plural_name %>.<%= verb %>.repository"
|
18
|
+
<%- when /update|destroy/ -%>
|
19
|
+
step :fecth_record, with: "<%= plural_name %>.<%= verb %>.repository"
|
20
|
+
<%- end -%>
|
21
|
+
|
22
|
+
step :<%= verb %>_record, with: "<%= plural_name %>.<%= verb %>.action"
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Operations
|
4
|
+
module Generators
|
5
|
+
class OperationGenerator < Rails::Generators::NamedBase
|
6
|
+
include Base::Generators::BaseGenerator
|
7
|
+
|
8
|
+
desc "Generates operation for operation"
|
9
|
+
|
10
|
+
hook_for :test_framework, as: "operations:operation"
|
11
|
+
|
12
|
+
source_root File.expand_path("operation/templates", __dir__)
|
13
|
+
|
14
|
+
def generate_files
|
15
|
+
super
|
16
|
+
|
17
|
+
template "operation.rb.erb", "#{root_file_path}/operations/#{plural_name}/#{verb}/operation.rb"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module <%= class_name.pluralize %>
|
4
|
+
module <%= verb.capitalize %>
|
5
|
+
class Register
|
6
|
+
|
7
|
+
extend Dry::Container::Mixin
|
8
|
+
|
9
|
+
namespace "<%= plural_name %>.<%= verb %>" do
|
10
|
+
<%- unless verb == "destroy" -%>
|
11
|
+
register "validation" do
|
12
|
+
Validation.new
|
13
|
+
end
|
14
|
+
<%- end -%>
|
15
|
+
|
16
|
+
register "repository" do
|
17
|
+
Repository.new
|
18
|
+
end
|
19
|
+
|
20
|
+
register "action" do
|
21
|
+
Action.new
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Operations
|
4
|
+
module Generators
|
5
|
+
class RegisterGenerator < Rails::Generators::NamedBase
|
6
|
+
include Base::Generators::BaseGenerator
|
7
|
+
|
8
|
+
source_root File.expand_path("register/templates", __dir__)
|
9
|
+
|
10
|
+
def generate_files
|
11
|
+
super
|
12
|
+
|
13
|
+
template "register.rb.erb", "#{root_file_path}/operations/#{plural_name}/#{verb}/register.rb"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "dry/transaction/operation"
|
4
|
+
require "dry/monads"
|
5
|
+
|
6
|
+
module <%= class_name.pluralize %>
|
7
|
+
module <%= verb.capitalize %>
|
8
|
+
class Repository
|
9
|
+
|
10
|
+
include Dry::Transaction::Operation
|
11
|
+
|
12
|
+
def call(input)
|
13
|
+
<%- case verb -%>
|
14
|
+
<%- when "create" -%>
|
15
|
+
instance = <%= class_name %>.new
|
16
|
+
<%- when /update|destroy/ -%>
|
17
|
+
instance = <%= class_name %>.find_by!(uuid: input[:id])
|
18
|
+
<%- end -%>
|
19
|
+
|
20
|
+
if instance
|
21
|
+
Success({instance:, input:})
|
22
|
+
else
|
23
|
+
Failure({input:})
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Operations
|
4
|
+
module Generators
|
5
|
+
class RepositoryGenerator < Rails::Generators::NamedBase
|
6
|
+
include Base::Generators::BaseGenerator
|
7
|
+
|
8
|
+
source_root File.expand_path("repository/templates", __dir__)
|
9
|
+
|
10
|
+
def generate_files
|
11
|
+
super
|
12
|
+
|
13
|
+
template "repository.rb.erb", "#{root_file_path}/operations/#{plural_name}/#{verb}/repository.rb"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Operations
|
4
|
+
module Generators
|
5
|
+
class ScaffoldGenerator < Rails::Generators::NamedBase
|
6
|
+
include Base::Generators::BaseGenerator
|
7
|
+
|
8
|
+
def call_generators
|
9
|
+
invoke "operations:action", [name, verb, fields], options if defined?(Dry::Validation)
|
10
|
+
unless verb == "destroy" || !defined?(Dry::Transaction)
|
11
|
+
invoke "operations:contract", [name, verb, fields],
|
12
|
+
options
|
13
|
+
end
|
14
|
+
unless verb == "destroy" || !defined?(Dry::Schema)
|
15
|
+
invoke "operations:schema", [name, verb, fields],
|
16
|
+
options
|
17
|
+
end
|
18
|
+
unless verb == "destroy" || !defined?(Dry::Validation)
|
19
|
+
invoke "operations:validation", [name, verb, fields],
|
20
|
+
options
|
21
|
+
end
|
22
|
+
invoke "operations:repository", [name, verb, fields], options if defined?(Dry::Transaction)
|
23
|
+
invoke "operations:register", [name, verb, fields], options if defined?(Dry::Container)
|
24
|
+
invoke "operations:operation", [name, verb, fields], options if defined?(Dry::Transaction)
|
25
|
+
end
|
26
|
+
|
27
|
+
class << self
|
28
|
+
def start(args, config)
|
29
|
+
ActionGenerator.start(args, config) if defined?(Dry::Validation)
|
30
|
+
ContractGenerator.start(args, config) if defined?(Dry::Transaction)
|
31
|
+
SchemaGenerator.start(args, config) if defined?(Dry::Schema)
|
32
|
+
ValidationGenerator.start(args, config) if defined?(Dry::Validation)
|
33
|
+
RepositoryGenerator.start(args, config) if defined?(Dry::Transaction)
|
34
|
+
RegisterGenerator.start(args, config) if defined?(Dry::Container)
|
35
|
+
OperationGenerator.start(args, config) if defined?(Dry::Transaction)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Sanitizes, coerces and type-checks input data
|
4
|
+
|
5
|
+
module <%= class_name.pluralize %>
|
6
|
+
module <%= verb.capitalize %>
|
7
|
+
Schema = Dry::Schema.Params do
|
8
|
+
<%- if verb =~ /update|all/ -%>
|
9
|
+
required(:id).filled(:<%= Operations.configuration.primary_key_type %>)
|
10
|
+
<%- end -%>
|
11
|
+
<%- @regular_parsed_fields.each do |field| -%>
|
12
|
+
<%= field.requirement %>(:<%= field.name %>).filled(:<%= field.type %>)
|
13
|
+
<%- end -%>
|
14
|
+
<%- @reference_parsed_fields.each do |field| -%>
|
15
|
+
<%= field.requirement %>(:<%= field.foreign_key %>).filled(:<%= Operations.configuration.primary_key_type %>)
|
16
|
+
<%- end -%>
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Operations
|
4
|
+
module Generators
|
5
|
+
class SchemaGenerator < Rails::Generators::NamedBase
|
6
|
+
include Base::Generators::BaseGenerator
|
7
|
+
|
8
|
+
desc "Generates schema for operation"
|
9
|
+
|
10
|
+
hook_for :test_framework, as: "operations:schema"
|
11
|
+
|
12
|
+
source_root File.expand_path("schema/templates", __dir__)
|
13
|
+
|
14
|
+
def generate_files
|
15
|
+
super
|
16
|
+
|
17
|
+
template "base/schema.rb.erb", "#{root_file_path}/operations/#{plural_name}/base/schema.rb"
|
18
|
+
template "schema.rb.erb", "#{root_file_path}/operations/#{plural_name}/#{verb}/schema.rb"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "operations"
|
4
|
+
|
5
|
+
Operations.configure do |config|
|
6
|
+
# config.primary_key_name = :id # default :id
|
7
|
+
# config.primary_key_type = :integer # default :integer
|
8
|
+
# config.foreign_key_suffix = "_id" # default "_id"
|
9
|
+
end
|
10
|
+
|
11
|
+
require "operations/generators/install_generator" if defined?(Dry)
|
12
|
+
require "operations/generators/scaffold_generator" if defined?(Dry)
|
13
|
+
require "operations/generators/schema_generator" if defined?(Dry::Schema)
|
14
|
+
require "operations/generators/action_generator" if defined?(Dry::Transaction)
|
15
|
+
require "operations/generators/contract_generator" if defined?(Dry::Validation)
|
16
|
+
require "operations/generators/validation_generator" if defined?(Dry::Validation)
|
17
|
+
require "operations/generators/repository_generator" if defined?(Dry::Transaction)
|
18
|
+
require "operations/generators/register_generator" if defined?(Dry::Container)
|
19
|
+
require "operations/generators/operation_generator" if defined?(Dry::Transaction)
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Operations
|
4
|
+
module Generators
|
5
|
+
class SetupGenerator < ::Rails::Generators::Base
|
6
|
+
hook_for :test_framework, as: "operations:setup" # Should call test_unit:operations:setup but doesn't ¯\_(ツ)_/¯
|
7
|
+
|
8
|
+
def copy_initializer_file
|
9
|
+
initializer "operation_generators.rb", File.read(File.expand_path("setup/templates/generators.rb.tt", __dir__))
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "dry/transaction/operation"
|
4
|
+
require "dry/validation"
|
5
|
+
require "dry/validation/contract"
|
6
|
+
|
7
|
+
module <%= class_name.pluralize %>
|
8
|
+
module <%= verb.capitalize %>
|
9
|
+
class Validation
|
10
|
+
|
11
|
+
include Dry::Transaction::Operation
|
12
|
+
|
13
|
+
def call(input)
|
14
|
+
params = Contract.new.call(input)
|
15
|
+
|
16
|
+
return Failure(params.errors) if params.failure?
|
17
|
+
|
18
|
+
Success(input)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Operations
|
4
|
+
module Generators
|
5
|
+
class ValidationGenerator < Rails::Generators::NamedBase
|
6
|
+
include Base::Generators::BaseGenerator
|
7
|
+
|
8
|
+
source_root File.expand_path("validation/templates", __dir__)
|
9
|
+
|
10
|
+
def generate_files
|
11
|
+
super
|
12
|
+
|
13
|
+
template "validation.rb.erb", "#{root_file_path}/operations/#{plural_name}/#{verb}/validation.rb"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Operations
|
4
|
+
module Generators
|
5
|
+
class <%= class_name %>Generator < Rails::Generators::NamedBase
|
6
|
+
include Base::Generators::BaseGenerator
|
7
|
+
|
8
|
+
desc "Generates <%= singular_name %> for operation"
|
9
|
+
|
10
|
+
<%- if options["hook_for_test_framework"] -%>
|
11
|
+
hook_for :test_framework, as: "operations:<%= singular_name %>"
|
12
|
+
<%- end -%>
|
13
|
+
|
14
|
+
source_root File.expand_path("<%= singular_name %>/templates", __dir__)
|
15
|
+
|
16
|
+
def generate_files
|
17
|
+
super
|
18
|
+
|
19
|
+
template "<%= singular_name %>.rb.erb", "#{root_file_path}/operations/#{plural_name}/#{verb}/<%= singular_name %>.rb"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Operations
|
4
|
+
module Generators
|
5
|
+
RSpec.describe <%= class_name %>Generator, type: :generator do
|
6
|
+
setup_default_destination
|
7
|
+
|
8
|
+
tests described_class
|
9
|
+
|
10
|
+
let(:<%= singular_name %>_path) { "app/operations/users/create/<%= singular_name %>.rb" }
|
11
|
+
|
12
|
+
subject(:<%= singular_name %>_generator) do
|
13
|
+
run_generator(
|
14
|
+
%w[
|
15
|
+
user
|
16
|
+
create
|
17
|
+
]
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "copy templates" do
|
22
|
+
<%= singular_name %>_generator
|
23
|
+
|
24
|
+
expect(File).to exist("#{destination_root}/#{<%= singular_name %>_path}")
|
25
|
+
end
|
26
|
+
|
27
|
+
it "uses the expected template files" do
|
28
|
+
<%= singular_name %>_generator
|
29
|
+
|
30
|
+
expect(content_for(<%= singular_name %>_path)).to match(/This is <%= singular_name %>.rb.erb/)
|
31
|
+
end
|
32
|
+
|
33
|
+
context "with component option" do
|
34
|
+
let(:<%= singular_name %>_path) { "components/identity/operations/users/create/<%= singular_name %>.rb" }
|
35
|
+
|
36
|
+
subject(:<%= singular_name %>_generator) do
|
37
|
+
run_generator(
|
38
|
+
%w[
|
39
|
+
user
|
40
|
+
create
|
41
|
+
--component identity/users
|
42
|
+
]
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "copy templates" do
|
47
|
+
<%= singular_name %>_generator
|
48
|
+
|
49
|
+
expect(File).to exist("#{destination_root}/#{<%= singular_name %>_path}")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/operations.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "zeitwerk"
|
4
|
+
loader = Zeitwerk::Loader.for_gem
|
5
|
+
loader.ignore("#{__dir__}/dry-operations.rb")
|
6
|
+
loader.setup
|
7
|
+
|
8
|
+
require "rails/generators"
|
9
|
+
|
10
|
+
require "operations/generators/setup_generator"
|
11
|
+
|
12
|
+
require "operations/base"
|
13
|
+
|
14
|
+
module Operations
|
15
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/operations/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "dry-operation_generators"
|
7
|
+
spec.version = Operations::VERSION
|
8
|
+
spec.authors = ["Joel Azemar"]
|
9
|
+
spec.email = ["joel.azemar@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "Generates Dry RB operation files"
|
12
|
+
spec.homepage = "https://github.com/joel/generators"
|
13
|
+
spec.license = "MIT"
|
14
|
+
spec.required_ruby_version = ">= 3.3.0"
|
15
|
+
|
16
|
+
# Specify which files should be added to the gem when it is released.
|
17
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
18
|
+
spec.files = Dir.chdir(__dir__) do
|
19
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
20
|
+
(File.expand_path(f) == __FILE__) ||
|
21
|
+
f.start_with?(*%w[bin/ test/ spec/ features/ .git .github .circleci appveyor Gemfile])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
spec.bindir = "exe"
|
25
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
26
|
+
spec.require_paths = ["lib"]
|
27
|
+
|
28
|
+
spec.add_dependency "dry-operation_generators-base"
|
29
|
+
spec.add_dependency "rails"
|
30
|
+
spec.add_dependency "zeitwerk"
|
31
|
+
|
32
|
+
# For more information and examples about making a new gem, check out our
|
33
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
34
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
35
|
+
end
|
data/sig/operations.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dry-operation_generators
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Joel Azemar
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-03-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: dry-operation_generators-base
|
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
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: zeitwerk
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- joel.azemar@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".rspec"
|
63
|
+
- ".rubocop.yml"
|
64
|
+
- ".rubocop_todo.yml"
|
65
|
+
- ".tool-versions"
|
66
|
+
- CHANGELOG.md
|
67
|
+
- CODE_OF_CONDUCT.md
|
68
|
+
- LICENSE.txt
|
69
|
+
- PRIVATE_NOTES.md
|
70
|
+
- README.md
|
71
|
+
- Rakefile
|
72
|
+
- config/initializers/dry_schema.rb
|
73
|
+
- lib/dry-operations.rb
|
74
|
+
- lib/operations.rb
|
75
|
+
- lib/operations/create_generator.rb
|
76
|
+
- lib/operations/generators/action/templates/action.rb.erb
|
77
|
+
- lib/operations/generators/action_generator.rb
|
78
|
+
- lib/operations/generators/contract/templates/base/contract.rb.erb
|
79
|
+
- lib/operations/generators/contract/templates/contract.rb.erb
|
80
|
+
- lib/operations/generators/contract_generator.rb
|
81
|
+
- lib/operations/generators/install/templates/application_contract.rb.tt
|
82
|
+
- lib/operations/generators/install/templates/application_schema.rb.tt
|
83
|
+
- lib/operations/generators/install/templates/dry_schema.rb.tt
|
84
|
+
- lib/operations/generators/install/templates/dry_types.rb.tt
|
85
|
+
- lib/operations/generators/install_generator.rb
|
86
|
+
- lib/operations/generators/operation/templates/operation.rb.erb
|
87
|
+
- lib/operations/generators/operation_generator.rb
|
88
|
+
- lib/operations/generators/register/templates/register.rb.erb
|
89
|
+
- lib/operations/generators/register_generator.rb
|
90
|
+
- lib/operations/generators/repository/templates/repository.rb.erb
|
91
|
+
- lib/operations/generators/repository_generator.rb
|
92
|
+
- lib/operations/generators/scaffold_generator.rb
|
93
|
+
- lib/operations/generators/schema/templates/base/schema.rb.erb
|
94
|
+
- lib/operations/generators/schema/templates/schema.rb.erb
|
95
|
+
- lib/operations/generators/schema_generator.rb
|
96
|
+
- lib/operations/generators/setup/templates/generators.rb.tt
|
97
|
+
- lib/operations/generators/setup_generator.rb
|
98
|
+
- lib/operations/generators/validation/templates/validation.rb.erb
|
99
|
+
- lib/operations/generators/validation_generator.rb
|
100
|
+
- lib/operations/templates/template_generator.rb.erb
|
101
|
+
- lib/operations/templates/template_generator_spec.rb.erb
|
102
|
+
- lib/operations/version.rb
|
103
|
+
- operation_generators.gemspec
|
104
|
+
- sig/operations.rbs
|
105
|
+
homepage: https://github.com/joel/generators
|
106
|
+
licenses:
|
107
|
+
- MIT
|
108
|
+
metadata:
|
109
|
+
rubygems_mfa_required: 'true'
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options: []
|
112
|
+
require_paths:
|
113
|
+
- lib
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: 3.3.0
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
requirements: []
|
125
|
+
rubygems_version: 3.5.3
|
126
|
+
signing_key:
|
127
|
+
specification_version: 4
|
128
|
+
summary: Generates Dry RB operation files
|
129
|
+
test_files: []
|