simpler_command 0.1.0 → 0.1.1
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.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +39 -0
- data/CHANGELOG.md +13 -2
- data/README.md +10 -0
- data/lib/generators/rspec/simpler_command/USAGE +10 -0
- data/lib/generators/rspec/simpler_command/simpler_command_generator.rb +44 -0
- data/lib/generators/rspec/simpler_command/templates/command_spec.rb.erb +36 -0
- data/lib/generators/simpler_command/USAGE +11 -0
- data/lib/generators/simpler_command/simpler_command_generator.rb +34 -0
- data/lib/generators/simpler_command/templates/command.rb.erb +41 -0
- data/lib/simpler_command.rb +2 -0
- data/lib/simpler_command/railtie.rb +11 -0
- data/lib/simpler_command/version.rb +1 -1
- data/simpler_command.gemspec +2 -1
- metadata +10 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3e58436c2fc52ade4f02eaa5b14e3f733b18862e362c3d1d63091b094e5646d
|
4
|
+
data.tar.gz: 8b86650fc4e3c88bd91ab2e2a4dafcef03ac3e20dc97eb7c90fd3da1f1426579
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7f3da130c71e7836afc642f2a675fc8eede194484e09fac52d3121b901bc93d16b70bd919c84cdfef326140ff23fa6b22befda1fdd2d65baf7d747875bf6f8c
|
7
|
+
data.tar.gz: 65516b45e517f4abfc25bcb5f8ede605c201ae29a7f75d8c7ee03fcbf9ba823780c2b862e5ca17cd48fb3a4b9cf4b54a2d20e6c19194ce1a5f34d9bb8e6ed0d1
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Ruby
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [ master ]
|
13
|
+
pull_request:
|
14
|
+
branches: [ master ]
|
15
|
+
|
16
|
+
jobs:
|
17
|
+
test:
|
18
|
+
|
19
|
+
runs-on: ubuntu-latest
|
20
|
+
|
21
|
+
steps:
|
22
|
+
- uses: actions/checkout@v2
|
23
|
+
- name: Set up Ruby
|
24
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
25
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
26
|
+
# uses: ruby/setup-ruby@v1
|
27
|
+
uses: ruby/setup-ruby@ec106b438a1ff6ff109590de34ddc62c540232e0
|
28
|
+
with:
|
29
|
+
ruby-version: 2.6
|
30
|
+
- name: Install dependencies
|
31
|
+
run: bundle install
|
32
|
+
- name: Run tests
|
33
|
+
run: bundle exec rake
|
34
|
+
- name: Run tests with ActiveSupport
|
35
|
+
env:
|
36
|
+
ACTIVE_SUPPORT_ENABLED: 1
|
37
|
+
run: bundle exec rake
|
38
|
+
- name: Run Code Quality Metrics
|
39
|
+
run: bundle exec rubocop
|
data/CHANGELOG.md
CHANGED
@@ -4,8 +4,19 @@
|
|
4
4
|
|
5
5
|
### Added
|
6
6
|
|
7
|
-
- Initial commit
|
8
|
-
|
9
7
|
### Changed
|
10
8
|
|
11
9
|
### Removed
|
10
|
+
|
11
|
+
## [0.1.1] - 2020-09-14
|
12
|
+
|
13
|
+
### Added
|
14
|
+
|
15
|
+
- Added simpler_command generator for Rails Applications
|
16
|
+
- Added rspec:simpler_command generator for testing SimplerCommand in Rails
|
17
|
+
|
18
|
+
## [0.1.0] - 2020-09-11
|
19
|
+
|
20
|
+
### Added
|
21
|
+
|
22
|
+
- Initial commit
|
data/README.md
CHANGED
@@ -67,6 +67,16 @@ class Albums::UpdateDescriptionController < ApplicationController
|
|
67
67
|
end
|
68
68
|
```
|
69
69
|
|
70
|
+
### Rails generator
|
71
|
+
|
72
|
+
For any Rails application, the easiest way to get started is by using the simpler_command generator.
|
73
|
+
|
74
|
+
```bash
|
75
|
+
bundle exec rails generator simpler_command AddSubscriptionToUser user subscription
|
76
|
+
```
|
77
|
+
|
78
|
+
This will generate the basic structure of your command inside the `app/commands` directory.
|
79
|
+
|
70
80
|
### The result object
|
71
81
|
|
72
82
|
Commands are Service Objects, built with the intent of following the principles of Command-query separation: every method should either be a command that performs an action, or a query that returns data to the caller, but not both.
|
@@ -0,0 +1,10 @@
|
|
1
|
+
Description:
|
2
|
+
Generates a spec for a Command (aka Service Object).
|
3
|
+
|
4
|
+
Provide additional command arguments for parameters used by the Command
|
5
|
+
|
6
|
+
Example:
|
7
|
+
rails generate rspec:simpler_command PublishArticle article
|
8
|
+
|
9
|
+
This will create:
|
10
|
+
spec/commands/publish_article_spec.rb
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "generators/rspec"
|
4
|
+
|
5
|
+
module Rspec
|
6
|
+
module Generators
|
7
|
+
# Rspec SimplerCommand Generator.
|
8
|
+
#
|
9
|
+
# Generates a spec for a command using SimplerCommand.
|
10
|
+
#
|
11
|
+
# Provide arguments to assist with boilerplate generation of your commands.
|
12
|
+
#
|
13
|
+
# == Examples
|
14
|
+
#
|
15
|
+
# rails generator rspec:simpler_command EnableMaintainance
|
16
|
+
# # => spec/commands/enable_maintainance_spec.rb
|
17
|
+
# rails generator rspec:simpler_command PublishArticle article
|
18
|
+
# # => spec/commands/publish_article_spec.rb
|
19
|
+
class SimplerCommand < Base
|
20
|
+
source_root File.expand_path("templates", __dir__)
|
21
|
+
|
22
|
+
argument :arguments, type: :array, default: [], banner: "command arguments"
|
23
|
+
|
24
|
+
def add_command_spec
|
25
|
+
template "command_spec.rb.erb", "spec/commands/#{file_name}_spec.rb"
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def argument_parameters
|
31
|
+
arguments.map(&:parameterize)
|
32
|
+
end
|
33
|
+
|
34
|
+
def method_call(call_name, parameters)
|
35
|
+
[
|
36
|
+
call_name,
|
37
|
+
parameters.any? ? "(" : "",
|
38
|
+
parameters.join(", "),
|
39
|
+
parameters.any? ? ")" : ""
|
40
|
+
].join
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require "rails_helper"
|
2
|
+
|
3
|
+
RSpec.describe <%= class_name %> do
|
4
|
+
describe ".call" do
|
5
|
+
subject(:response) { described_class.<%= method_call("call", argument_parameters) %> }
|
6
|
+
|
7
|
+
context "with valid parameters" do
|
8
|
+
# TODO: setup valid parameters
|
9
|
+
<%- argument_parameters.each do |arg| -%>
|
10
|
+
let(:<%= arg %>) { instance_double(<%= arg.classify %>) }
|
11
|
+
<%- end -%>
|
12
|
+
|
13
|
+
it { is_expected.to be_success }
|
14
|
+
it { expect(response.result).to be_nil }
|
15
|
+
<%- argument_parameters.each do |arg| -%>
|
16
|
+
|
17
|
+
it "interacts with <%= arg %>" do
|
18
|
+
pending "add expectations for interacting with <%= arg %>"
|
19
|
+
|
20
|
+
response
|
21
|
+
|
22
|
+
expect(<%= arg %>).to have_received(:example)
|
23
|
+
end
|
24
|
+
<%- end -%>
|
25
|
+
end
|
26
|
+
|
27
|
+
context "with invalid parameters" do
|
28
|
+
# TODO: setup invalid parameters
|
29
|
+
<%- argument_parameters.each do |arg| -%>
|
30
|
+
let(:<%= arg %>) { instance_double(<%= arg.classify %>) }
|
31
|
+
<%- end -%>
|
32
|
+
|
33
|
+
it { is_expected.to be_failure }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
Description:
|
2
|
+
Generates a Command (aka Service Object) using SimplerCommand.
|
3
|
+
|
4
|
+
Provide additional command arguments for parameters used by the Command
|
5
|
+
|
6
|
+
Example:
|
7
|
+
rails generate simpler_command PublishArticle article
|
8
|
+
|
9
|
+
This will create:
|
10
|
+
app/commands/publish_article.rb
|
11
|
+
spec/commands/publish_article_spec.rb
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# SimplerCommand Generator.
|
4
|
+
#
|
5
|
+
# Generates a command using SimplerCommand.
|
6
|
+
#
|
7
|
+
# Provide arguments to assist with boilerplate generation of your commands.
|
8
|
+
#
|
9
|
+
# == Examples
|
10
|
+
#
|
11
|
+
# rails generator simpler_command EnableMaintainance # => app/commands/enable_maintainance.rb
|
12
|
+
# rails generator simpler_command PublishArticle article # => app/commands/publish_article.rb
|
13
|
+
class SimplerCommandGenerator < Rails::Generators::NamedBase
|
14
|
+
source_root File.expand_path("templates", __dir__)
|
15
|
+
|
16
|
+
argument :arguments, type: :array, default: [], banner: "command arguments"
|
17
|
+
|
18
|
+
def add_command_template
|
19
|
+
template "command.rb.erb", "app/commands/#{file_name}.rb"
|
20
|
+
end
|
21
|
+
|
22
|
+
hook_for :test_framework
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def argument_parameters
|
27
|
+
arguments.map(&:parameterize)
|
28
|
+
end
|
29
|
+
|
30
|
+
def method_call(call_name, parameters)
|
31
|
+
parameters ||= []
|
32
|
+
[call_name, parameters.any? ? "(" : "", parameters.join(", "), parameters.any? ? ")" : ""].join
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# <%= class_name %> command.
|
2
|
+
#
|
3
|
+
# === Examples
|
4
|
+
#
|
5
|
+
# <%= class_name %>.<%= method_call "call", argument_parameters %> # => response object with success? and result, or failure?
|
6
|
+
# <%= class_name %>.<%= method_call "call!", argument_parameters %> # => result, or thrown SimpleCommand::Failure
|
7
|
+
class <%= class_name %>
|
8
|
+
# put SimplerCommand before the class' ancestors chain
|
9
|
+
prepend SimplerCommand
|
10
|
+
|
11
|
+
# Uncomment for Rails I18n Error Translations
|
12
|
+
# include ActiveModel::Validations
|
13
|
+
|
14
|
+
def <%= method_call "initialize", argument_parameters %>
|
15
|
+
<%- argument_parameters.each do |arg| -%>
|
16
|
+
@<%= arg %> = <%= arg %>
|
17
|
+
<%- end -%>
|
18
|
+
end
|
19
|
+
|
20
|
+
def call
|
21
|
+
# TODO: Implement <%= class_name %> command<%- if arguments.any? -%>, e.g. <% end %>
|
22
|
+
<%- if arguments.any? -%>
|
23
|
+
# unless [<%= argument_parameters.join(", ") %>].all?(&:valid?)
|
24
|
+
<%- argument_parameters.each do |arg| -%>
|
25
|
+
# errors.merge! <%= arg %>.errors
|
26
|
+
<%- end -%>
|
27
|
+
# return
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
# # do something...
|
31
|
+
#
|
32
|
+
# nil
|
33
|
+
<%- end -%>
|
34
|
+
end
|
35
|
+
<%- if arguments.any? -%>
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
attr_reader <%= argument_parameters.map { |arg| ":#{arg}" }.join(", ") %>
|
40
|
+
<%- end -%>
|
41
|
+
end
|
data/lib/simpler_command.rb
CHANGED
@@ -4,6 +4,8 @@ require "simpler_command/version"
|
|
4
4
|
require "simpler_command/string_utils"
|
5
5
|
require "simpler_command/errors"
|
6
6
|
|
7
|
+
require "simpler_command/railtie" if defined? Rails::Railtie
|
8
|
+
|
7
9
|
# Provides a simple structure for Commands (Services).
|
8
10
|
#
|
9
11
|
# Prepend SimplerCommand to your Command (Service) objects and implemente a call methods.
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SimplerCommand
|
4
|
+
# SimplerCommand Railtie.
|
5
|
+
class Railtie < ::Rails::Railtie
|
6
|
+
generators do
|
7
|
+
require "generators/simpler_command/simpler_command_generator"
|
8
|
+
require "generators/rspec/simpler_command/simpler_command_generator" if defined? RSpec::Rails
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/simpler_command.gemspec
CHANGED
@@ -8,7 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.authors = ["Ben Morrall"]
|
9
9
|
spec.email = ["bemo56@hotmail.com"]
|
10
10
|
|
11
|
-
spec.summary = "Yet another simple and standardized way to build and use Commands
|
11
|
+
spec.summary = "Yet another simple and standardized way to build and use Commands" \
|
12
|
+
" (aka Service Objects)"
|
12
13
|
spec.homepage = "https://github.com/bmorrall/simpler_command"
|
13
14
|
spec.license = "MIT"
|
14
15
|
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simpler_command
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Morrall
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-09-
|
11
|
+
date: 2020-09-14 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -17,6 +17,7 @@ executables: []
|
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
|
+
- ".github/workflows/ruby.yml"
|
20
21
|
- ".gitignore"
|
21
22
|
- ".rspec"
|
22
23
|
- ".rubocop.yml"
|
@@ -29,8 +30,15 @@ files:
|
|
29
30
|
- Rakefile
|
30
31
|
- bin/console
|
31
32
|
- bin/setup
|
33
|
+
- lib/generators/rspec/simpler_command/USAGE
|
34
|
+
- lib/generators/rspec/simpler_command/simpler_command_generator.rb
|
35
|
+
- lib/generators/rspec/simpler_command/templates/command_spec.rb.erb
|
36
|
+
- lib/generators/simpler_command/USAGE
|
37
|
+
- lib/generators/simpler_command/simpler_command_generator.rb
|
38
|
+
- lib/generators/simpler_command/templates/command.rb.erb
|
32
39
|
- lib/simpler_command.rb
|
33
40
|
- lib/simpler_command/errors.rb
|
41
|
+
- lib/simpler_command/railtie.rb
|
34
42
|
- lib/simpler_command/string_utils.rb
|
35
43
|
- lib/simpler_command/version.rb
|
36
44
|
- simpler_command.gemspec
|