steel_wheel 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/ruby.yml +48 -0
  3. data/.gitignore +12 -0
  4. data/.rspec +3 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +7 -0
  7. data/CODE_OF_CONDUCT.md +74 -0
  8. data/Gemfile +6 -0
  9. data/Gemfile.lock +146 -0
  10. data/LICENSE.txt +21 -0
  11. data/README.md +44 -0
  12. data/Rakefile +6 -0
  13. data/assets/action_diagram.png +0 -0
  14. data/bin/console +14 -0
  15. data/bin/setup +8 -0
  16. data/lib/generators/steel_wheel/command/USAGE +8 -0
  17. data/lib/generators/steel_wheel/command/command_generator.rb +16 -0
  18. data/lib/generators/steel_wheel/command/templates/command_template.rb +3 -0
  19. data/lib/generators/steel_wheel/generic_generator.rb +23 -0
  20. data/lib/generators/steel_wheel/handler/USAGE +8 -0
  21. data/lib/generators/steel_wheel/handler/handler_generator.rb +16 -0
  22. data/lib/generators/steel_wheel/handler/templates/handler_template.rb +15 -0
  23. data/lib/generators/steel_wheel/params/USAGE +8 -0
  24. data/lib/generators/steel_wheel/params/params_generator.rb +16 -0
  25. data/lib/generators/steel_wheel/params/templates/params_template.rb +3 -0
  26. data/lib/generators/steel_wheel/query/USAGE +8 -0
  27. data/lib/generators/steel_wheel/query/query_generator.rb +16 -0
  28. data/lib/generators/steel_wheel/query/templates/query_template.rb +3 -0
  29. data/lib/steel_wheel/command.rb +18 -0
  30. data/lib/steel_wheel/handler.rb +50 -0
  31. data/lib/steel_wheel/params.rb +3 -0
  32. data/lib/steel_wheel/query.rb +14 -0
  33. data/lib/steel_wheel/response.rb +29 -0
  34. data/lib/steel_wheel/skip_active_model_errors_keys.rb +42 -0
  35. data/lib/steel_wheel/version.rb +3 -0
  36. data/lib/steel_wheel.rb +17 -0
  37. data/steel_wheel.gemspec +53 -0
  38. metadata +228 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1f78a33640673ae355d747b2d3ad8f609a44f68309de8002e04c210da95a7ff6
4
+ data.tar.gz: 4a558908edbce43e2ba3cf9e050123aa80718c07dc029591861166831f5d7eb2
5
+ SHA512:
6
+ metadata.gz: b5bead07689527757142b3d5b16ccad39868bc2d7ccab38cb2ef90c2120916cb6e7a0776575c22e67b744549415e4102798d4de970f303bb7d3b8151cbb07eb5
7
+ data.tar.gz: 6415108dcb2e119d0872d663e3ba1586a5d2794f26d549544c3b8761692d54b550369401ccb9298d28049689589894aea8c15a435bb8684c4ea73ef15828df80
@@ -0,0 +1,48 @@
1
+ name: Ruby
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ test:
7
+
8
+ runs-on: ubuntu-latest
9
+
10
+ steps:
11
+ - uses: actions/checkout@v2
12
+ - name: Set up Ruby
13
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
14
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
15
+ # uses: ruby/setup-ruby@v1
16
+ uses: ruby/setup-ruby@21351ecc0a7c196081abca5dc55b08f085efe09a
17
+ with:
18
+ ruby-version: 2.6
19
+ - name: Install dependencies
20
+ run: bundle install
21
+ - name: Run tests
22
+ run: bundle exec rake
23
+
24
+ coverage:
25
+ needs: [ test ]
26
+ name: coverage
27
+ runs-on: ubuntu-latest
28
+ steps:
29
+ - uses: actions/checkout@v2
30
+ - name: Set up Ruby
31
+ uses: ruby/setup-ruby@21351ecc0a7c196081abca5dc55b08f085efe09a
32
+ with:
33
+ ruby-version: 2.6
34
+ - name: Install dependencies
35
+ run: bundle install
36
+ - name: Setup Code Climate test-reporter
37
+ run: |
38
+ curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
39
+ chmod +x ./cc-test-reporter
40
+ ./cc-test-reporter before-build
41
+ - name: Build and test with RSpec
42
+ env:
43
+ CC_TEST_REPORTER_ID: 4bb114295e4e80ad0f42b2f30b7611f0459c1cbdc7a74a0fe6fa437a543796d9
44
+ run: bundle exec rake
45
+ - name: Publish code coverage
46
+ run: |
47
+ export GIT_BRANCH="master"
48
+ ./cc-test-reporter after-build -r 4bb114295e4e80ad0f42b2f30b7611f0459c1cbdc7a74a0fe6fa437a543796d9
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.4.0
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.0
7
+ before_install: gem install bundler -v 1.17.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at andriy.baran.v@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in steel_wheel.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,146 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ steel_wheel (0.5.0)
5
+ easy_params (~> 0.1.0)
6
+ flow_object (~> 0.3.1)
7
+ memery (~> 1)
8
+ railties (>= 3.2, < 8)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ actionpack (5.2.6)
14
+ actionview (= 5.2.6)
15
+ activesupport (= 5.2.6)
16
+ rack (~> 2.0, >= 2.0.8)
17
+ rack-test (>= 0.6.3)
18
+ rails-dom-testing (~> 2.0)
19
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
20
+ actionview (5.2.6)
21
+ activesupport (= 5.2.6)
22
+ builder (~> 3.1)
23
+ erubi (~> 1.4)
24
+ rails-dom-testing (~> 2.0)
25
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
26
+ activemodel (5.2.6)
27
+ activesupport (= 5.2.6)
28
+ activesupport (5.2.6)
29
+ concurrent-ruby (~> 1.0, >= 1.0.2)
30
+ i18n (>= 0.7, < 2)
31
+ minitest (~> 5.1)
32
+ tzinfo (~> 1.1)
33
+ builder (3.2.4)
34
+ coderay (1.1.2)
35
+ concurrent-ruby (1.1.9)
36
+ crass (1.0.6)
37
+ diff-lcs (1.3)
38
+ docile (1.3.5)
39
+ dry-configurable (0.11.6)
40
+ concurrent-ruby (~> 1.0)
41
+ dry-core (~> 0.4, >= 0.4.7)
42
+ dry-equalizer (~> 0.2)
43
+ dry-container (0.7.2)
44
+ concurrent-ruby (~> 1.0)
45
+ dry-configurable (~> 0.1, >= 0.1.3)
46
+ dry-core (0.4.9)
47
+ concurrent-ruby (~> 1.0)
48
+ dry-equalizer (0.3.0)
49
+ dry-inflector (0.2.0)
50
+ dry-logic (1.0.8)
51
+ concurrent-ruby (~> 1.0)
52
+ dry-core (~> 0.2)
53
+ dry-equalizer (~> 0.2)
54
+ dry-struct (1.3.0)
55
+ dry-core (~> 0.4, >= 0.4.4)
56
+ dry-equalizer (~> 0.3)
57
+ dry-types (~> 1.3)
58
+ ice_nine (~> 0.11)
59
+ dry-types (1.4.0)
60
+ concurrent-ruby (~> 1.0)
61
+ dry-container (~> 0.3)
62
+ dry-core (~> 0.4, >= 0.4.4)
63
+ dry-equalizer (~> 0.3)
64
+ dry-inflector (~> 0.1, >= 0.1.2)
65
+ dry-logic (~> 1.0, >= 1.0.2)
66
+ easy_params (0.1.1)
67
+ activemodel (>= 3.2, < 6.1)
68
+ dry-struct (~> 1.3.0)
69
+ dry-types (~> 1.4.0)
70
+ erubi (1.10.0)
71
+ flow_object (0.3.1)
72
+ hospodar (~> 1)
73
+ hospodar (1.0.1)
74
+ dry-inflector (~> 0.1)
75
+ i18n (1.9.0)
76
+ concurrent-ruby (~> 1.0)
77
+ ice_nine (0.11.2)
78
+ json (2.5.1)
79
+ loofah (2.13.0)
80
+ crass (~> 1.0.2)
81
+ nokogiri (>= 1.5.9)
82
+ memery (1.3.0)
83
+ ruby2_keywords (~> 0.0.2)
84
+ method_source (0.9.2)
85
+ mini_portile2 (2.4.0)
86
+ minitest (5.15.0)
87
+ nokogiri (1.10.10)
88
+ mini_portile2 (~> 2.4.0)
89
+ pry (0.12.2)
90
+ coderay (~> 1.1.0)
91
+ method_source (~> 0.9.0)
92
+ rack (2.2.3)
93
+ rack-test (1.1.0)
94
+ rack (>= 1.0, < 3)
95
+ rails-dom-testing (2.0.3)
96
+ activesupport (>= 4.2.0)
97
+ nokogiri (>= 1.6)
98
+ rails-html-sanitizer (1.4.2)
99
+ loofah (~> 2.3)
100
+ railties (5.2.6)
101
+ actionpack (= 5.2.6)
102
+ activesupport (= 5.2.6)
103
+ method_source
104
+ rake (>= 0.8.7)
105
+ thor (>= 0.19.0, < 2.0)
106
+ rake (13.0.3)
107
+ rspec (3.9.0)
108
+ rspec-core (~> 3.9.0)
109
+ rspec-expectations (~> 3.9.0)
110
+ rspec-mocks (~> 3.9.0)
111
+ rspec-core (3.9.0)
112
+ rspec-support (~> 3.9.0)
113
+ rspec-expectations (3.9.0)
114
+ diff-lcs (>= 1.2.0, < 2.0)
115
+ rspec-support (~> 3.9.0)
116
+ rspec-mocks (3.9.0)
117
+ diff-lcs (>= 1.2.0, < 2.0)
118
+ rspec-support (~> 3.9.0)
119
+ rspec-support (3.9.0)
120
+ rspec_vars_helper (0.1.0)
121
+ rspec (>= 2.4)
122
+ ruby2_keywords (0.0.5)
123
+ simplecov (0.17.0)
124
+ docile (~> 1.1)
125
+ json (>= 1.8, < 3)
126
+ simplecov-html (~> 0.10.0)
127
+ simplecov-html (0.10.2)
128
+ thor (1.2.1)
129
+ thread_safe (0.3.6)
130
+ tzinfo (1.2.9)
131
+ thread_safe (~> 0.1)
132
+
133
+ PLATFORMS
134
+ ruby
135
+
136
+ DEPENDENCIES
137
+ bundler (~> 1.17)
138
+ pry (~> 0.10)
139
+ rake (>= 12.3.3)
140
+ rspec (~> 3.0)
141
+ rspec_vars_helper (~> 0.1)
142
+ simplecov (= 0.17)
143
+ steel_wheel!
144
+
145
+ BUNDLED WITH
146
+ 1.17.0
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Andrii Baran
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,44 @@
1
+ # SteelWheel
2
+ [![Maintainability](https://api.codeclimate.com/v1/badges/a197758aa1cfde54f0e1/maintainability)](https://codeclimate.com/github/andriy-baran/steel_wheel/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/a197758aa1cfde54f0e1/test_coverage)](https://codeclimate.com/github/andriy-baran/steel_wheel/test_coverage)
3
+
4
+ Allows to operate on any sequence of procedures as on linked list. It means that inserting and deleting any list/element into/from similar lists is very efficient. And a rich callbacks system gives entire control over the execution. Currently there is one example implemented. It helps organize common procedures in a Rails' controlers.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'steel_wheel'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install steel_wheel
21
+
22
+ ## Usage
23
+
24
+ [Getting started on Rails](https://github.com/andriy-baran/steel_wheel/wiki/Getting-started-on-Rails)
25
+
26
+ [Wiki](https://github.com/andriy-baran/steel_wheel/wiki)
27
+
28
+ ## Development
29
+
30
+ 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.
31
+
32
+ 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).
33
+
34
+ ## Contributing
35
+
36
+ Bug reports and pull requests are welcome on GitHub at https://github.com/andriy-baran/steel_wheel. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
41
+
42
+ ## Code of Conduct
43
+
44
+ Everyone interacting in the SteelWheel project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/andriy-baran/steel_wheel/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
Binary file
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'steel_wheel'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Generates commands files
3
+
4
+ Example:
5
+ rails generate steel_wheel:command Thing
6
+
7
+ This will create:
8
+ app/commands/thing_command.rb
@@ -0,0 +1,16 @@
1
+ require_relative '../generic_generator'
2
+
3
+ module SteelWheel
4
+ class CommandGenerator < GenericGenerator
5
+ setup_templates_root('command/templates')
6
+
7
+ on_revoke do
8
+ template 'command_template.rb', "app/commands/#{file_path}_command.rb"
9
+ end
10
+
11
+ on_invoke do
12
+ empty_directory Pathname.new('app/commands').join(*class_path)
13
+ template 'command_template.rb', "app/commands/#{file_path}_command.rb"
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ class <%= class_name %>Command < SteelWheel::Command
2
+
3
+ end
@@ -0,0 +1,23 @@
1
+ module SteelWheel
2
+ class GenericGenerator < Rails::Generators::NamedBase
3
+ def self.setup_templates_root(templates_relative_path)
4
+ source_root File.expand_path(templates_relative_path, __dir__)
5
+ end
6
+
7
+ def self.on_revoke(&block)
8
+ block_given? ? @on_revoke = block : @on_revoke
9
+ end
10
+
11
+ def self.on_invoke(&block)
12
+ block_given? ? @on_invoke = block : @on_invoke
13
+ end
14
+
15
+ def copy_files
16
+ if behavior == :revoke
17
+ instance_eval(&self.class.on_revoke)
18
+ elsif behavior == :invoke
19
+ instance_eval(&self.class.on_invoke)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Generates operations files
3
+
4
+ Example:
5
+ rails generate steel_wheel:handler Thing
6
+
7
+ This will create:
8
+ app/handlers/thing_handler.rb
@@ -0,0 +1,16 @@
1
+ require_relative '../generic_generator'
2
+
3
+ module SteelWheel
4
+ class HandlerGenerator < GenericGenerator
5
+ setup_templates_root('handler/templates')
6
+
7
+ on_revoke do
8
+ template 'handler_template.rb', "app/handlers/#{file_path}_handler.rb"
9
+ end
10
+
11
+ on_invoke do
12
+ empty_directory Pathname.new('app/handlers').join(*class_path)
13
+ template 'handler_template.rb', "app/handlers/#{file_path}_handler.rb"
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,15 @@
1
+ class <%= class_name %>Handler < ApplicationHandler
2
+ params_input do
3
+
4
+ end
5
+
6
+ command_stage do
7
+ def call
8
+ # NOOP
9
+ end
10
+ end
11
+
12
+ def on_success
13
+ flow.call
14
+ end
15
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Generates operations files
3
+
4
+ Example:
5
+ rails generate steel_wheel:params Thing
6
+
7
+ This will create:
8
+ app/params/thing_params.rb
@@ -0,0 +1,16 @@
1
+ require_relative '../generic_generator'
2
+
3
+ module SteelWheel
4
+ class ParamsGenerator < GenericGenerator
5
+ setup_templates_root('params/templates')
6
+
7
+ on_revoke do
8
+ template 'params_template.rb', "app/params/#{file_path}_params.rb"
9
+ end
10
+
11
+ on_invoke do
12
+ empty_directory Pathname.new('app/params').join(*class_path)
13
+ template 'params_template.rb', "app/params/#{file_path}_params.rb"
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ class <%= class_name %>Params < SteelWheel::Params
2
+
3
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Generates queries files
3
+
4
+ Example:
5
+ rails generate steel_wheel:query Thing
6
+
7
+ This will create:
8
+ app/queries/thing_query.rb
@@ -0,0 +1,16 @@
1
+ require_relative '../generic_generator'
2
+
3
+ module SteelWheel
4
+ class CommandGenerator < GenericGenerator
5
+ setup_templates_root('query/templates')
6
+
7
+ on_revoke do
8
+ template 'query_template.rb', "app/queries/#{file_path}_query.rb"
9
+ end
10
+
11
+ on_invoke do
12
+ empty_directory Pathname.new('app/queries').join(*class_path)
13
+ template 'query_template.rb', "app/queries/#{file_path}_query.rb"
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ class <%= class_name %>Query < SteelWheel::Query
2
+
3
+ end
@@ -0,0 +1,18 @@
1
+ module SteelWheel
2
+ class Command
3
+ include Memery
4
+ include ActiveModel::Validations
5
+
6
+ def self.name
7
+ 'SteelWheel::Command'
8
+ end
9
+
10
+ def http_status
11
+ errors.keys.first
12
+ end
13
+
14
+ def call
15
+ # NOOP
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,50 @@
1
+ module SteelWheel
2
+ class Handler < FlowObject::Base
3
+ from :params
4
+ to :response
5
+
6
+ input :params, base_class: SteelWheel::Params
7
+ flow do
8
+ stage :query, base_class: SteelWheel::Query
9
+ stage :command, base_class: SteelWheel::Command
10
+ end
11
+ output :response, base_class: SteelWheel::Response
12
+
13
+ def self.halt_flow?(object, id)
14
+ !object.valid?
15
+ end
16
+
17
+ def on_params_failure
18
+ output.status = :bad_request
19
+ output.errors.merge!(output.params.errors)
20
+ end
21
+
22
+ def on_query_failure
23
+ output.status = output.query.http_status
24
+ output.errors.merge!(output.query.errors)
25
+ end
26
+
27
+ def on_command_failure
28
+ output.status = output.command.http_status
29
+ output.errors.merge!(output.command.errors)
30
+ end
31
+
32
+ def on_success
33
+ # NOOP
34
+ end
35
+
36
+ def self.handle(input:, flow: :main, &block)
37
+ call(input: input, flow: flow) do |callbacks|
38
+ callbacks.flow_initialized(&block) if block
39
+ end
40
+ end
41
+
42
+ alias_method(:flow, :output)
43
+ class << self
44
+ alias_method :params, :params_input
45
+ alias_method :query, :query_stage
46
+ alias_method :command, :command_stage
47
+ alias_method :response, :response_output
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,3 @@
1
+ module SteelWheel
2
+ class Params < EasyParams::Base; end
3
+ end
@@ -0,0 +1,14 @@
1
+ module SteelWheel
2
+ class Query
3
+ include Memery
4
+ include ActiveModel::Validations
5
+
6
+ def self.name
7
+ 'SteelWheel::Query'
8
+ end
9
+
10
+ def http_status
11
+ errors.keys.first
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,29 @@
1
+ module SteelWheel
2
+ class Response
3
+ attr_accessor :status
4
+ attr_writer :errors
5
+ include ActiveModel::Validations
6
+
7
+ def self.generic_validation_keys(*keys)
8
+ include SteelWheel::SkipActiveModelErrorsKeys[*keys]
9
+ end
10
+
11
+ generic_validation_keys(:not_found, :forbidden, :unprocessable_entity)
12
+
13
+ def self.name
14
+ 'SteelWheel::Response'
15
+ end
16
+
17
+ def initialize
18
+ @status = :ok
19
+ end
20
+
21
+ def success?
22
+ errors.empty?
23
+ end
24
+
25
+ def valid?
26
+ success?
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,42 @@
1
+ module SteelWheel
2
+ module SkipActiveModelErrorsKeys
3
+ def self.build_module
4
+ mod = Module.new do
5
+ class << self
6
+ attr_accessor :skip_keys
7
+
8
+ def extended(klass)
9
+ klass.include self
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+ def self.patch_errors_method_on_instance(mod, klass)
16
+ class << klass
17
+ alias_method :__new__, :new
18
+ end
19
+
20
+ klass.define_singleton_method :new do |*args|
21
+ instance = __new__(*args)
22
+ instance.errors.define_singleton_method :full_message do |attribute, message|
23
+ return message if mod.skip_keys.include?(attribute)
24
+ super(attribute, message)
25
+ end
26
+ instance
27
+ end
28
+ end
29
+
30
+ def self.[](*skip_keys)
31
+ mod = build_module
32
+ mod.skip_keys = skip_keys
33
+ builder = self
34
+ mod.module_eval do
35
+ define_singleton_method(:included) do |klass|
36
+ builder.patch_errors_method_on_instance(self, klass)
37
+ end
38
+ end
39
+ mod
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,3 @@
1
+ module SteelWheel
2
+ VERSION = '0.5.0'.freeze
3
+ end
@@ -0,0 +1,17 @@
1
+ require 'ostruct'
2
+ require 'easy_params'
3
+ require 'flow_object'
4
+ require 'json'
5
+ require 'active_model'
6
+ require 'memery'
7
+ require 'steel_wheel/skip_active_model_errors_keys'
8
+ require 'steel_wheel/params'
9
+ require 'steel_wheel/query'
10
+ require 'steel_wheel/command'
11
+ require 'steel_wheel/response'
12
+ require 'steel_wheel/handler'
13
+ require 'steel_wheel/version'
14
+
15
+ module SteelWheel
16
+ class Error < StandardError; end
17
+ end
@@ -0,0 +1,53 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'steel_wheel/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'steel_wheel'
7
+ spec.version = SteelWheel::VERSION
8
+ spec.authors = ['Andrii Baran']
9
+ spec.email = ['andriy.baran.v@gmail.com']
10
+
11
+ spec.summary = 'Adds operations to your rails code'
12
+ spec.description = %(Tiny DSL for code in controllers)
13
+ spec.homepage = 'https://github.com/andriy-baran/steel_wheel'
14
+ spec.license = 'MIT'
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
20
+
21
+ spec.metadata['homepage_uri'] = spec.homepage
22
+ spec.metadata['source_code_uri'] = 'https://github.com/andriy-baran/steel_wheel'
23
+ # spec.metadata['changelog_uri'] = 'TODO: Put your gem's CHANGELOG.md URL here.'
24
+ else
25
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
26
+ 'public gem pushes.'
27
+ end
28
+
29
+ # Specify which files should be added to the gem when it is released.
30
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
31
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
32
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
33
+ end
34
+ spec.bindir = 'exe'
35
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
36
+ spec.require_paths = ['lib']
37
+ spec.required_ruby_version = '>= 2.4'
38
+
39
+ version_string = ['>= 3.2', '< 8']
40
+
41
+ spec.add_runtime_dependency 'railties', version_string
42
+
43
+ spec.add_dependency 'memery', '~> 1'
44
+ spec.add_dependency 'easy_params', '~> 0.1.0'
45
+ spec.add_dependency 'flow_object', '~> 0.3.1'
46
+
47
+ spec.add_development_dependency 'bundler', '~> 1.17'
48
+ spec.add_development_dependency 'pry', '~> 0.10'
49
+ spec.add_development_dependency 'rake', '>= 12.3.3'
50
+ spec.add_development_dependency 'rspec', '~> 3.0'
51
+ spec.add_development_dependency 'simplecov', '0.17'
52
+ spec.add_development_dependency 'rspec_vars_helper', '~> 0.1'
53
+ end
metadata ADDED
@@ -0,0 +1,228 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: steel_wheel
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ platform: ruby
6
+ authors:
7
+ - Andrii Baran
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-01-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '8'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '3.2'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '8'
33
+ - !ruby/object:Gem::Dependency
34
+ name: memery
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1'
47
+ - !ruby/object:Gem::Dependency
48
+ name: easy_params
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: 0.1.0
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: 0.1.0
61
+ - !ruby/object:Gem::Dependency
62
+ name: flow_object
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: 0.3.1
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 0.3.1
75
+ - !ruby/object:Gem::Dependency
76
+ name: bundler
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '1.17'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '1.17'
89
+ - !ruby/object:Gem::Dependency
90
+ name: pry
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '0.10'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '0.10'
103
+ - !ruby/object:Gem::Dependency
104
+ name: rake
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: 12.3.3
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: 12.3.3
117
+ - !ruby/object:Gem::Dependency
118
+ name: rspec
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '3.0'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: '3.0'
131
+ - !ruby/object:Gem::Dependency
132
+ name: simplecov
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - '='
136
+ - !ruby/object:Gem::Version
137
+ version: '0.17'
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - '='
143
+ - !ruby/object:Gem::Version
144
+ version: '0.17'
145
+ - !ruby/object:Gem::Dependency
146
+ name: rspec_vars_helper
147
+ requirement: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - "~>"
150
+ - !ruby/object:Gem::Version
151
+ version: '0.1'
152
+ type: :development
153
+ prerelease: false
154
+ version_requirements: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - "~>"
157
+ - !ruby/object:Gem::Version
158
+ version: '0.1'
159
+ description: Tiny DSL for code in controllers
160
+ email:
161
+ - andriy.baran.v@gmail.com
162
+ executables: []
163
+ extensions: []
164
+ extra_rdoc_files: []
165
+ files:
166
+ - ".github/workflows/ruby.yml"
167
+ - ".gitignore"
168
+ - ".rspec"
169
+ - ".ruby-version"
170
+ - ".travis.yml"
171
+ - CODE_OF_CONDUCT.md
172
+ - Gemfile
173
+ - Gemfile.lock
174
+ - LICENSE.txt
175
+ - README.md
176
+ - Rakefile
177
+ - assets/action_diagram.png
178
+ - bin/console
179
+ - bin/setup
180
+ - lib/generators/steel_wheel/command/USAGE
181
+ - lib/generators/steel_wheel/command/command_generator.rb
182
+ - lib/generators/steel_wheel/command/templates/command_template.rb
183
+ - lib/generators/steel_wheel/generic_generator.rb
184
+ - lib/generators/steel_wheel/handler/USAGE
185
+ - lib/generators/steel_wheel/handler/handler_generator.rb
186
+ - lib/generators/steel_wheel/handler/templates/handler_template.rb
187
+ - lib/generators/steel_wheel/params/USAGE
188
+ - lib/generators/steel_wheel/params/params_generator.rb
189
+ - lib/generators/steel_wheel/params/templates/params_template.rb
190
+ - lib/generators/steel_wheel/query/USAGE
191
+ - lib/generators/steel_wheel/query/query_generator.rb
192
+ - lib/generators/steel_wheel/query/templates/query_template.rb
193
+ - lib/steel_wheel.rb
194
+ - lib/steel_wheel/command.rb
195
+ - lib/steel_wheel/handler.rb
196
+ - lib/steel_wheel/params.rb
197
+ - lib/steel_wheel/query.rb
198
+ - lib/steel_wheel/response.rb
199
+ - lib/steel_wheel/skip_active_model_errors_keys.rb
200
+ - lib/steel_wheel/version.rb
201
+ - steel_wheel.gemspec
202
+ homepage: https://github.com/andriy-baran/steel_wheel
203
+ licenses:
204
+ - MIT
205
+ metadata:
206
+ allowed_push_host: https://rubygems.org
207
+ homepage_uri: https://github.com/andriy-baran/steel_wheel
208
+ source_code_uri: https://github.com/andriy-baran/steel_wheel
209
+ post_install_message:
210
+ rdoc_options: []
211
+ require_paths:
212
+ - lib
213
+ required_ruby_version: !ruby/object:Gem::Requirement
214
+ requirements:
215
+ - - ">="
216
+ - !ruby/object:Gem::Version
217
+ version: '2.4'
218
+ required_rubygems_version: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
223
+ requirements: []
224
+ rubygems_version: 3.2.30
225
+ signing_key:
226
+ specification_version: 4
227
+ summary: Adds operations to your rails code
228
+ test_files: []