auxiliary_rails 0.1.6 → 0.3.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/.gitlab-ci.yml +26 -0
- data/.rubocop.yml +27 -2
- data/.rubocop_todo.yml +5 -15
- data/.yardopts +5 -0
- data/CHANGELOG.md +39 -3
- data/CONTRIBUTING.md +0 -6
- data/Gemfile.lock +116 -92
- data/README.md +213 -6
- data/auxiliary_rails.gemspec +13 -12
- data/bin/rubocop +29 -0
- data/bitbucket-pipelines.yml +35 -0
- data/lib/auxiliary_rails.rb +5 -3
- data/lib/auxiliary_rails/application/command.rb +56 -0
- data/lib/auxiliary_rails/application/error.rb +10 -0
- data/lib/auxiliary_rails/application/form.rb +30 -0
- data/lib/auxiliary_rails/application/query.rb +71 -0
- data/lib/auxiliary_rails/cli.rb +18 -5
- data/lib/auxiliary_rails/concerns/errorable.rb +22 -0
- data/lib/auxiliary_rails/concerns/performable.rb +128 -0
- data/lib/auxiliary_rails/version.rb +1 -1
- data/lib/generators/auxiliary_rails/api_resource_generator.rb +10 -1
- data/lib/generators/auxiliary_rails/command_generator.rb +44 -0
- data/lib/generators/auxiliary_rails/install_commands_generator.rb +6 -1
- data/lib/generators/auxiliary_rails/install_generator.rb +0 -1
- data/lib/generators/auxiliary_rails/templates/apis/api_entity_template.rb.erb +2 -1
- data/lib/generators/auxiliary_rails/templates/apis/api_resource_spec_template.rb.erb +36 -9
- data/lib/generators/auxiliary_rails/templates/apis/api_resource_template.rb.erb +12 -6
- data/lib/generators/auxiliary_rails/templates/application_error_template.rb +1 -1
- data/lib/generators/auxiliary_rails/templates/commands/application_command_template.rb +2 -0
- data/lib/generators/auxiliary_rails/templates/commands/command_spec_template.rb +11 -0
- data/lib/generators/auxiliary_rails/templates/commands/command_template.rb +6 -0
- data/lib/generators/auxiliary_rails/templates/commands/commands.en_template.yml +5 -0
- data/templates/rails/elementary.rb +40 -10
- metadata +81 -24
- data/lib/auxiliary_rails/abstract_command.rb +0 -96
- data/lib/auxiliary_rails/abstract_error.rb +0 -7
- data/lib/generators/auxiliary_rails/install_rubocop_generator.rb +0 -29
- data/lib/generators/auxiliary_rails/templates/application_command_template.rb +0 -2
- data/lib/generators/auxiliary_rails/templates/rubocop/rubocop_auxiliary_rails_template.yml +0 -51
- data/lib/generators/auxiliary_rails/templates/rubocop/rubocop_template.yml +0 -7
@@ -12,21 +12,25 @@ module <%= api_module_name %>::Resources
|
|
12
12
|
end
|
13
13
|
|
14
14
|
resource :<%= plural_name %> do
|
15
|
-
desc 'Returns
|
15
|
+
desc 'Returns a collection of <%= plural_name %>' do
|
16
|
+
success <%= entity_class_name %>
|
17
|
+
end
|
16
18
|
get do
|
17
|
-
# TODO: authorize
|
19
|
+
# TODO: authorize <%= class_name %>, :index?
|
18
20
|
present collection,
|
19
21
|
with: <%= entity_class_name %>
|
20
22
|
end
|
21
23
|
|
22
|
-
desc 'Creates a <%= class_name %>'
|
24
|
+
desc 'Creates a <%= class_name %>' do
|
25
|
+
success <%= entity_class_name %>
|
26
|
+
end
|
23
27
|
params do
|
24
28
|
requires :<%= singular_name %>, type: Hash do
|
25
29
|
# TODO: define resource params or remove `params` block
|
26
30
|
end
|
27
31
|
end
|
28
32
|
post do
|
29
|
-
@<%= singular_name %> = <%= class_name %>.new(
|
33
|
+
@<%= singular_name %> = <%= class_name %>.new(params[:<%= singular_name %>])
|
30
34
|
# TODO: authorize resource, :create?
|
31
35
|
resource.save!
|
32
36
|
present resource,
|
@@ -44,14 +48,16 @@ module <%= api_module_name %>::Resources
|
|
44
48
|
with: <%= entity_class_name %>
|
45
49
|
end
|
46
50
|
|
47
|
-
desc 'Updates a <%= class_name %>'
|
51
|
+
desc 'Updates a <%= class_name %>' do
|
52
|
+
success <%= entity_class_name %>
|
53
|
+
end
|
48
54
|
params do
|
49
55
|
requires :<%= singular_name %>, type: Hash do
|
50
56
|
# TODO: define resource params or remove `params` block
|
51
57
|
end
|
52
58
|
end
|
53
59
|
put do
|
54
|
-
resource.assign_attributes(
|
60
|
+
resource.assign_attributes(params[:<%= singular_name %>])
|
55
61
|
# TODO: authorize resource, :update?
|
56
62
|
resource.save!
|
57
63
|
present resource,
|
@@ -1,2 +1,2 @@
|
|
1
|
-
class ApplicationError < AuxiliaryRails::
|
1
|
+
class ApplicationError < AuxiliaryRails::Application::Error
|
2
2
|
end
|
@@ -3,21 +3,43 @@ gsub_file 'Gemfile', /^\s*#.*$\n/, ''
|
|
3
3
|
gsub_file 'Gemfile', /^.*coffee.*$\n/, ''
|
4
4
|
gsub_file 'Gemfile', /^.*jbuilder.*$\n/, ''
|
5
5
|
gsub_file 'Gemfile', /^.*tzinfo-data.*$\n/, ''
|
6
|
+
gsub_file 'Gemfile', /^group :development, :test do\n.*byebug.*\nend\n\n/, ''
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
gsub_file '.gitignore', /^\s*#.*$\n/, ''
|
9
|
+
gsub_file 'config/routes.rb', /^\s*#.*$\n/, ''
|
10
|
+
|
11
|
+
gsub_file 'config/database.yml', /^\s*#.*$\n/, ''
|
12
|
+
gsub_file 'config/database.yml', /^\s*pool.*$\n/, <<-FILE
|
13
|
+
host: <%= ENV['DATABASE_HOST'] %>
|
14
|
+
username: <%= ENV['DATABASE_USERNAME'] %>
|
15
|
+
pool: <%= ENV.fetch('RAILS_MAX_THREADS') { 5 } %>
|
16
|
+
FILE
|
17
|
+
|
18
|
+
# Create RuboCop files
|
19
|
+
file '.rubocop.yml', <<~FILE
|
20
|
+
inherit_gem:
|
21
|
+
rubocop-ergoserv:
|
22
|
+
- config/default.yml
|
23
|
+
FILE
|
24
|
+
|
25
|
+
run 'touch .env'
|
26
|
+
append_file '.gitignore', <<~FILE
|
27
|
+
.env*.local
|
28
|
+
FILE
|
29
|
+
|
30
|
+
# Gemfile additions
|
31
|
+
gem 'auxiliary_rails'
|
10
32
|
|
11
33
|
gem_group :development, :test do
|
34
|
+
gem 'byebug'
|
35
|
+
gem 'dotenv-rails'
|
12
36
|
gem 'factory_bot_rails'
|
13
37
|
gem 'faker'
|
14
|
-
gem 'pry-byebug'
|
15
38
|
gem 'pry-rails'
|
16
39
|
gem 'rspec-rails'
|
17
|
-
gem 'rubocop'
|
18
|
-
|
19
|
-
|
20
|
-
gem 'rubocop-rspec'
|
40
|
+
gem 'rubocop-ergoserv',
|
41
|
+
git: 'https://github.com/ergoserv/rubocop-ergoserv',
|
42
|
+
require: false
|
21
43
|
end
|
22
44
|
|
23
45
|
gem_group :test do
|
@@ -28,6 +50,14 @@ end
|
|
28
50
|
after_bundle do
|
29
51
|
# ensure using the latest versions of gems
|
30
52
|
run 'bundle update'
|
31
|
-
|
32
|
-
|
53
|
+
run 'bundle binstubs rubocop'
|
54
|
+
|
55
|
+
generate 'rspec:install'
|
56
|
+
|
57
|
+
generate 'controller', 'pages', 'home',
|
58
|
+
'--no-assets',
|
59
|
+
'--no-helper',
|
60
|
+
'--no-test-framework',
|
61
|
+
'--skip-routes'
|
62
|
+
route "root to: 'pages#home'"
|
33
63
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: auxiliary_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitry Babenko
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2020-10-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -40,49 +40,49 @@ dependencies:
|
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '0'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
|
-
name:
|
43
|
+
name: rake
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
|
-
- - "
|
46
|
+
- - ">="
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: '
|
48
|
+
version: '0'
|
49
49
|
type: :development
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
|
-
- - "
|
53
|
+
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: '
|
55
|
+
version: '0'
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
|
-
name:
|
57
|
+
name: rspec
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
60
|
- - "~>"
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: '
|
62
|
+
version: '3.8'
|
63
63
|
type: :development
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
67
|
- - "~>"
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: '
|
69
|
+
version: '3.8'
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
|
-
name:
|
71
|
+
name: rubocop
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
74
|
- - "~>"
|
75
75
|
- !ruby/object:Gem::Version
|
76
|
-
version: '
|
76
|
+
version: '0.80'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
81
|
- - "~>"
|
82
82
|
- !ruby/object:Gem::Version
|
83
|
-
version: '
|
83
|
+
version: '0.80'
|
84
84
|
- !ruby/object:Gem::Dependency
|
85
|
-
name: rubocop
|
85
|
+
name: rubocop-performance
|
86
86
|
requirement: !ruby/object:Gem::Requirement
|
87
87
|
requirements:
|
88
88
|
- - ">="
|
@@ -96,7 +96,7 @@ dependencies:
|
|
96
96
|
- !ruby/object:Gem::Version
|
97
97
|
version: '0'
|
98
98
|
- !ruby/object:Gem::Dependency
|
99
|
-
name: rubocop-
|
99
|
+
name: rubocop-rspec
|
100
100
|
requirement: !ruby/object:Gem::Requirement
|
101
101
|
requirements:
|
102
102
|
- - ">="
|
@@ -110,19 +110,67 @@ dependencies:
|
|
110
110
|
- !ruby/object:Gem::Version
|
111
111
|
version: '0'
|
112
112
|
- !ruby/object:Gem::Dependency
|
113
|
-
name:
|
113
|
+
name: dry-core
|
114
114
|
requirement: !ruby/object:Gem::Requirement
|
115
115
|
requirements:
|
116
116
|
- - ">="
|
117
117
|
- !ruby/object:Gem::Version
|
118
118
|
version: '0'
|
119
|
-
type: :
|
119
|
+
type: :runtime
|
120
120
|
prerelease: false
|
121
121
|
version_requirements: !ruby/object:Gem::Requirement
|
122
122
|
requirements:
|
123
123
|
- - ">="
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: dry-initializer
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
type: :runtime
|
134
|
+
prerelease: false
|
135
|
+
version_requirements: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
- !ruby/object:Gem::Dependency
|
141
|
+
name: dry-initializer-rails
|
142
|
+
requirement: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
type: :runtime
|
148
|
+
prerelease: false
|
149
|
+
version_requirements: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
- !ruby/object:Gem::Dependency
|
155
|
+
name: rails
|
156
|
+
requirement: !ruby/object:Gem::Requirement
|
157
|
+
requirements:
|
158
|
+
- - ">="
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: '5.2'
|
161
|
+
- - "<"
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
version: '7'
|
164
|
+
type: :runtime
|
165
|
+
prerelease: false
|
166
|
+
version_requirements: !ruby/object:Gem::Requirement
|
167
|
+
requirements:
|
168
|
+
- - ">="
|
169
|
+
- !ruby/object:Gem::Version
|
170
|
+
version: '5.2'
|
171
|
+
- - "<"
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '7'
|
126
174
|
- !ruby/object:Gem::Dependency
|
127
175
|
name: thor
|
128
176
|
requirement: !ruby/object:Gem::Requirement
|
@@ -149,11 +197,13 @@ extensions: []
|
|
149
197
|
extra_rdoc_files: []
|
150
198
|
files:
|
151
199
|
- ".gitignore"
|
200
|
+
- ".gitlab-ci.yml"
|
152
201
|
- ".rspec"
|
153
202
|
- ".rubocop.yml"
|
154
203
|
- ".rubocop_todo.yml"
|
155
204
|
- ".ruby-version"
|
156
205
|
- ".travis.yml"
|
206
|
+
- ".yardopts"
|
157
207
|
- CHANGELOG.md
|
158
208
|
- CONTRIBUTING.md
|
159
209
|
- Gemfile
|
@@ -165,27 +215,34 @@ files:
|
|
165
215
|
- auxiliary_rails.gemspec
|
166
216
|
- bin/auxiliary_rails
|
167
217
|
- bin/console
|
218
|
+
- bin/rubocop
|
168
219
|
- bin/setup
|
220
|
+
- bitbucket-pipelines.yml
|
169
221
|
- lib/auxiliary_rails.rb
|
170
|
-
- lib/auxiliary_rails/
|
171
|
-
- lib/auxiliary_rails/
|
222
|
+
- lib/auxiliary_rails/application/command.rb
|
223
|
+
- lib/auxiliary_rails/application/error.rb
|
224
|
+
- lib/auxiliary_rails/application/form.rb
|
225
|
+
- lib/auxiliary_rails/application/query.rb
|
172
226
|
- lib/auxiliary_rails/cli.rb
|
227
|
+
- lib/auxiliary_rails/concerns/errorable.rb
|
228
|
+
- lib/auxiliary_rails/concerns/performable.rb
|
173
229
|
- lib/auxiliary_rails/railtie.rb
|
174
230
|
- lib/auxiliary_rails/version.rb
|
175
231
|
- lib/auxiliary_rails/view_helpers.rb
|
176
232
|
- lib/generators/auxiliary_rails/api_resource_generator.rb
|
233
|
+
- lib/generators/auxiliary_rails/command_generator.rb
|
177
234
|
- lib/generators/auxiliary_rails/install_commands_generator.rb
|
178
235
|
- lib/generators/auxiliary_rails/install_errors_generator.rb
|
179
236
|
- lib/generators/auxiliary_rails/install_generator.rb
|
180
|
-
- lib/generators/auxiliary_rails/install_rubocop_generator.rb
|
181
237
|
- lib/generators/auxiliary_rails/templates/apis/api_entity_template.rb.erb
|
182
238
|
- lib/generators/auxiliary_rails/templates/apis/api_helper_template.rb.erb
|
183
239
|
- lib/generators/auxiliary_rails/templates/apis/api_resource_spec_template.rb.erb
|
184
240
|
- lib/generators/auxiliary_rails/templates/apis/api_resource_template.rb.erb
|
185
|
-
- lib/generators/auxiliary_rails/templates/application_command_template.rb
|
186
241
|
- lib/generators/auxiliary_rails/templates/application_error_template.rb
|
187
|
-
- lib/generators/auxiliary_rails/templates/
|
188
|
-
- lib/generators/auxiliary_rails/templates/
|
242
|
+
- lib/generators/auxiliary_rails/templates/commands/application_command_template.rb
|
243
|
+
- lib/generators/auxiliary_rails/templates/commands/command_spec_template.rb
|
244
|
+
- lib/generators/auxiliary_rails/templates/commands/command_template.rb
|
245
|
+
- lib/generators/auxiliary_rails/templates/commands/commands.en_template.yml
|
189
246
|
- templates/rails/elementary.rb
|
190
247
|
homepage: https://github.com/ergoserv/auxiliary_rails
|
191
248
|
licenses:
|
@@ -193,7 +250,7 @@ licenses:
|
|
193
250
|
metadata:
|
194
251
|
homepage_uri: https://github.com/ergoserv/auxiliary_rails
|
195
252
|
source_code_uri: https://github.com/ergoserv/auxiliary_rails
|
196
|
-
changelog_uri: https://github.com/ergoserv/auxiliary_rails/
|
253
|
+
changelog_uri: https://github.com/ergoserv/auxiliary_rails/releases
|
197
254
|
post_install_message:
|
198
255
|
rdoc_options: []
|
199
256
|
require_paths:
|
@@ -1,96 +0,0 @@
|
|
1
|
-
require 'active_model'
|
2
|
-
|
3
|
-
module AuxiliaryRails
|
4
|
-
class AbstractCommand
|
5
|
-
include ActiveModel::Model
|
6
|
-
include ActiveModel::Attributes
|
7
|
-
|
8
|
-
def self.call(*args)
|
9
|
-
new(*args).call
|
10
|
-
end
|
11
|
-
|
12
|
-
def call
|
13
|
-
raise NotImplementedError
|
14
|
-
end
|
15
|
-
|
16
|
-
def errors
|
17
|
-
@errors ||= ActiveModel::Errors.new(self)
|
18
|
-
end
|
19
|
-
|
20
|
-
def failure?
|
21
|
-
status?(:failure)
|
22
|
-
end
|
23
|
-
|
24
|
-
def status?(value)
|
25
|
-
ensure_execution!
|
26
|
-
|
27
|
-
status == value&.to_sym
|
28
|
-
end
|
29
|
-
|
30
|
-
def success?
|
31
|
-
status?(:success)
|
32
|
-
end
|
33
|
-
|
34
|
-
def transaction(&block)
|
35
|
-
ActiveRecord::Base.transaction(&block) if block_given?
|
36
|
-
end
|
37
|
-
|
38
|
-
# Method for ActiveModel::Errors
|
39
|
-
def read_attribute_for_validation(attr_name)
|
40
|
-
if attr_name == :command
|
41
|
-
self
|
42
|
-
else
|
43
|
-
attribute(attr_name)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
# Method for ActiveModel::Translation
|
48
|
-
def self.i18n_scope
|
49
|
-
:commands
|
50
|
-
end
|
51
|
-
|
52
|
-
protected
|
53
|
-
|
54
|
-
attr_accessor :status
|
55
|
-
|
56
|
-
def ensure_empty_errors!
|
57
|
-
return if errors.empty?
|
58
|
-
|
59
|
-
error!("`#{self.class}` contains errors.")
|
60
|
-
end
|
61
|
-
|
62
|
-
def ensure_empty_status!
|
63
|
-
return if status.nil?
|
64
|
-
|
65
|
-
error!("`#{self.class}` was already executed.")
|
66
|
-
end
|
67
|
-
|
68
|
-
def ensure_execution!
|
69
|
-
return if status.present?
|
70
|
-
|
71
|
-
error!("`#{self.class}` was not executed yet.")
|
72
|
-
end
|
73
|
-
|
74
|
-
def error!(message = nil)
|
75
|
-
message ||= "`#{self.class}` raised error."
|
76
|
-
raise ApplicationError, message
|
77
|
-
end
|
78
|
-
|
79
|
-
def failure!(message = nil)
|
80
|
-
ensure_empty_status!
|
81
|
-
|
82
|
-
errors.add(:command, :failed, message: message) unless message.nil?
|
83
|
-
|
84
|
-
self.status = :failure
|
85
|
-
self
|
86
|
-
end
|
87
|
-
|
88
|
-
def success!
|
89
|
-
ensure_empty_errors!
|
90
|
-
ensure_empty_status!
|
91
|
-
|
92
|
-
self.status = :success
|
93
|
-
self
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|