auxiliary_rails 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/.gitlab-ci.yml +26 -0
  3. data/.rubocop.yml +11 -2
  4. data/.rubocop_todo.yml +13 -9
  5. data/.yardopts +5 -0
  6. data/CHANGELOG.md +19 -2
  7. data/CONTRIBUTING.md +0 -6
  8. data/Gemfile.lock +20 -16
  9. data/README.md +204 -3
  10. data/auxiliary_rails.gemspec +7 -5
  11. data/bin/rubocop +3 -0
  12. data/lib/auxiliary_rails.rb +5 -3
  13. data/lib/auxiliary_rails/application/command.rb +56 -0
  14. data/lib/auxiliary_rails/application/error.rb +10 -0
  15. data/lib/auxiliary_rails/application/form.rb +30 -0
  16. data/lib/auxiliary_rails/application/query.rb +78 -0
  17. data/lib/auxiliary_rails/cli.rb +19 -5
  18. data/lib/auxiliary_rails/concerns/performable.rb +141 -0
  19. data/lib/auxiliary_rails/version.rb +1 -1
  20. data/lib/generators/auxiliary_rails/install_commands_generator.rb +5 -0
  21. data/lib/generators/auxiliary_rails/install_generator.rb +0 -1
  22. data/lib/generators/auxiliary_rails/templates/application_error_template.rb +1 -1
  23. data/lib/generators/auxiliary_rails/templates/commands/application_command_template.rb +1 -1
  24. data/lib/generators/auxiliary_rails/templates/commands/command_template.rb +2 -2
  25. data/lib/generators/auxiliary_rails/templates/commands/commands.en_template.yml +5 -0
  26. data/templates/rails/elementary.rb +45 -9
  27. metadata +43 -11
  28. data/lib/auxiliary_rails/abstract_command.rb +0 -95
  29. data/lib/auxiliary_rails/abstract_error.rb +0 -7
  30. data/lib/generators/auxiliary_rails/install_rubocop_generator.rb +0 -29
  31. data/lib/generators/auxiliary_rails/templates/rubocop/rubocop_auxiliary_rails_template.yml +0 -65
  32. data/lib/generators/auxiliary_rails/templates/rubocop/rubocop_template.yml +0 -11
@@ -1,2 +1,2 @@
1
- class ApplicationError < AuxiliaryRails::AbstractError
1
+ class ApplicationError < AuxiliaryRails::Application::Error
2
2
  end
@@ -1,2 +1,2 @@
1
- class ApplicationCommand < AuxiliaryRails::AbstractCommand
1
+ class ApplicationCommand < AuxiliaryRails::Application::Command
2
2
  end
@@ -1,6 +1,6 @@
1
1
  class <%= command_class_name %> < ApplicationCommand
2
- def call
3
- # TODO: implement <%= command_class_name %>.call method
2
+ def perform
3
+ # TODO: implement <%= command_class_name %>.perform method
4
4
  success!
5
5
  end
6
6
  end
@@ -0,0 +1,5 @@
1
+ en:
2
+ commands:
3
+ errors:
4
+ messages:
5
+ validation_failed: validation failed
@@ -3,22 +3,51 @@ 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
- gem 'auxiliary_rails',
8
- git: 'https://github.com/ergoserv/auxiliary_rails',
9
- branch: 'develop'
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
+ file 'bin/rubocop', <<~FILE
26
+ #!/usr/bin/env bash
27
+
28
+ bundle exec rubocop "$@"
29
+ FILE
30
+ chmod 'bin/rubocop', 0o755
31
+
32
+ run 'touch .env'
33
+ append_file '.gitignore', <<~FILE
34
+ .env*.local
35
+ FILE
36
+
37
+ # Gemfile additions
38
+ gem 'auxiliary_rails'
10
39
 
11
40
  gem_group :development, :test do
41
+ gem 'byebug'
12
42
  gem 'dotenv-rails'
13
43
  gem 'factory_bot_rails'
14
44
  gem 'faker'
15
45
  gem 'pry-byebug'
16
46
  gem 'pry-rails'
17
47
  gem 'rspec-rails'
18
- gem 'rubocop'
19
- gem 'rubocop-performance'
20
- gem 'rubocop-rails'
21
- gem 'rubocop-rspec'
48
+ gem 'rubocop-ergoserv',
49
+ git: 'https://github.com/ergoserv/rubocop-ergoserv',
50
+ require: false
22
51
  end
23
52
 
24
53
  gem_group :test do
@@ -29,6 +58,13 @@ end
29
58
  after_bundle do
30
59
  # ensure using the latest versions of gems
31
60
  run 'bundle update'
32
- rails_command 'generate auxiliary_rails:install_rubocop --no-specify-gems'
33
- rails_command 'generate rspec:install'
61
+
62
+ generate :controller, 'pages', 'home',
63
+ '--no-assets',
64
+ '--no-helper',
65
+ '--no-test-framework',
66
+ '--skip-routes'
67
+ route "root to: 'pages#home'"
68
+
69
+ generate 'rspec:install'
34
70
  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.2.0
4
+ version: 0.3.0
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: 2020-01-05 00:00:00.000000000 Z
12
+ date: 2020-03-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -89,6 +89,20 @@ dependencies:
89
89
  version: '3.8'
90
90
  - !ruby/object:Gem::Dependency
91
91
  name: rubocop
92
+ requirement: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: '0.79'
97
+ type: :development
98
+ prerelease: false
99
+ version_requirements: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: '0.79'
104
+ - !ruby/object:Gem::Dependency
105
+ name: rubocop-performance
92
106
  requirement: !ruby/object:Gem::Requirement
93
107
  requirements:
94
108
  - - ">="
@@ -102,7 +116,7 @@ dependencies:
102
116
  - !ruby/object:Gem::Version
103
117
  version: '0'
104
118
  - !ruby/object:Gem::Dependency
105
- name: rubocop-performance
119
+ name: rubocop-rspec
106
120
  requirement: !ruby/object:Gem::Requirement
107
121
  requirements:
108
122
  - - ">="
@@ -116,13 +130,27 @@ dependencies:
116
130
  - !ruby/object:Gem::Version
117
131
  version: '0'
118
132
  - !ruby/object:Gem::Dependency
119
- name: rubocop-rspec
133
+ name: dry-core
120
134
  requirement: !ruby/object:Gem::Requirement
121
135
  requirements:
122
136
  - - ">="
123
137
  - !ruby/object:Gem::Version
124
138
  version: '0'
125
- type: :development
139
+ type: :runtime
140
+ prerelease: false
141
+ version_requirements: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ - !ruby/object:Gem::Dependency
147
+ name: dry-initializer
148
+ requirement: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ type: :runtime
126
154
  prerelease: false
127
155
  version_requirements: !ruby/object:Gem::Requirement
128
156
  requirements:
@@ -169,11 +197,13 @@ extensions: []
169
197
  extra_rdoc_files: []
170
198
  files:
171
199
  - ".gitignore"
200
+ - ".gitlab-ci.yml"
172
201
  - ".rspec"
173
202
  - ".rubocop.yml"
174
203
  - ".rubocop_todo.yml"
175
204
  - ".ruby-version"
176
205
  - ".travis.yml"
206
+ - ".yardopts"
177
207
  - CHANGELOG.md
178
208
  - CONTRIBUTING.md
179
209
  - Gemfile
@@ -185,11 +215,15 @@ files:
185
215
  - auxiliary_rails.gemspec
186
216
  - bin/auxiliary_rails
187
217
  - bin/console
218
+ - bin/rubocop
188
219
  - bin/setup
189
220
  - lib/auxiliary_rails.rb
190
- - lib/auxiliary_rails/abstract_command.rb
191
- - lib/auxiliary_rails/abstract_error.rb
221
+ - lib/auxiliary_rails/application/command.rb
222
+ - lib/auxiliary_rails/application/error.rb
223
+ - lib/auxiliary_rails/application/form.rb
224
+ - lib/auxiliary_rails/application/query.rb
192
225
  - lib/auxiliary_rails/cli.rb
226
+ - lib/auxiliary_rails/concerns/performable.rb
193
227
  - lib/auxiliary_rails/railtie.rb
194
228
  - lib/auxiliary_rails/version.rb
195
229
  - lib/auxiliary_rails/view_helpers.rb
@@ -198,7 +232,6 @@ files:
198
232
  - lib/generators/auxiliary_rails/install_commands_generator.rb
199
233
  - lib/generators/auxiliary_rails/install_errors_generator.rb
200
234
  - lib/generators/auxiliary_rails/install_generator.rb
201
- - lib/generators/auxiliary_rails/install_rubocop_generator.rb
202
235
  - lib/generators/auxiliary_rails/templates/apis/api_entity_template.rb.erb
203
236
  - lib/generators/auxiliary_rails/templates/apis/api_helper_template.rb.erb
204
237
  - lib/generators/auxiliary_rails/templates/apis/api_resource_spec_template.rb.erb
@@ -207,8 +240,7 @@ files:
207
240
  - lib/generators/auxiliary_rails/templates/commands/application_command_template.rb
208
241
  - lib/generators/auxiliary_rails/templates/commands/command_spec_template.rb
209
242
  - lib/generators/auxiliary_rails/templates/commands/command_template.rb
210
- - lib/generators/auxiliary_rails/templates/rubocop/rubocop_auxiliary_rails_template.yml
211
- - lib/generators/auxiliary_rails/templates/rubocop/rubocop_template.yml
243
+ - lib/generators/auxiliary_rails/templates/commands/commands.en_template.yml
212
244
  - templates/rails/elementary.rb
213
245
  homepage: https://github.com/ergoserv/auxiliary_rails
214
246
  licenses:
@@ -216,7 +248,7 @@ licenses:
216
248
  metadata:
217
249
  homepage_uri: https://github.com/ergoserv/auxiliary_rails
218
250
  source_code_uri: https://github.com/ergoserv/auxiliary_rails
219
- changelog_uri: https://github.com/ergoserv/auxiliary_rails/blob/master/CHANGELOG.md
251
+ changelog_uri: https://github.com/ergoserv/auxiliary_rails/releases
220
252
  post_install_message:
221
253
  rdoc_options: []
222
254
  require_paths:
@@ -1,95 +0,0 @@
1
- require 'dry-initializer-rails'
2
- require 'active_model'
3
-
4
- module AuxiliaryRails
5
- class AbstractCommand
6
- extend Dry::Initializer
7
- include ActiveModel::Validations
8
-
9
- def self.call(*args)
10
- new(*args).call
11
- end
12
-
13
- def call
14
- raise NotImplementedError
15
- end
16
-
17
- def failure?
18
- status?(:failure)
19
- end
20
-
21
- def status?(value)
22
- ensure_execution!
23
-
24
- status == value&.to_sym
25
- end
26
-
27
- def success?
28
- status?(:success)
29
- end
30
-
31
- # Shortcut for `ActiveRecord::Base.transaction`
32
- def transaction(&block)
33
- ActiveRecord::Base.transaction(&block) if block_given?
34
- end
35
-
36
- # Method for ActiveModel::Errors
37
- def read_attribute_for_validation(attr_name)
38
- attr_name = attr_name.to_sym
39
- if attr_name == :command
40
- self
41
- else
42
- self.class.dry_initializer.attributes(self)[attr_name]
43
- end
44
- end
45
-
46
- # Method for ActiveModel::Translation
47
- def self.i18n_scope
48
- :commands
49
- end
50
-
51
- protected
52
-
53
- attr_accessor :status
54
-
55
- def ensure_empty_errors!
56
- return if errors.empty?
57
-
58
- error!("`#{self.class}` contains errors.")
59
- end
60
-
61
- def ensure_empty_status!
62
- return if status.nil?
63
-
64
- error!("`#{self.class}` was already executed.")
65
- end
66
-
67
- def ensure_execution!
68
- return if status.present?
69
-
70
- error!("`#{self.class}` was not executed yet.")
71
- end
72
-
73
- def error!(message = nil)
74
- message ||= "`#{self.class}` raised error."
75
- raise ApplicationError, message
76
- end
77
-
78
- def failure!(message = nil)
79
- ensure_empty_status!
80
-
81
- errors.add(:command, :failed, message: message) unless message.nil?
82
-
83
- self.status = :failure
84
- self
85
- end
86
-
87
- def success!
88
- ensure_empty_errors!
89
- ensure_empty_status!
90
-
91
- self.status = :success
92
- self
93
- end
94
- end
95
- end
@@ -1,7 +0,0 @@
1
- module AuxiliaryRails
2
- class AbstractError < StandardError
3
- def self.wrap(error)
4
- new(error.message)
5
- end
6
- end
7
- end
@@ -1,29 +0,0 @@
1
- require 'rails'
2
-
3
- module AuxiliaryRails
4
- class InstallRubocopGenerator < ::Rails::Generators::Base
5
- class_option :specify_gems,
6
- type: :boolean,
7
- default: true,
8
- desc: 'Indicates if `rubocop` gem needs to be added to Gemfile'
9
- source_root File.expand_path('templates/rubocop', __dir__)
10
-
11
- def copy_config_files
12
- copy_file 'rubocop_template.yml',
13
- '.rubocop.yml'
14
- copy_file 'rubocop_auxiliary_rails_template.yml',
15
- '.rubocop_auxiliary_rails.yml'
16
- end
17
-
18
- def specify_gems_dependency
19
- return unless options[:specify_gems]
20
-
21
- gem_group :development, :test do
22
- gem 'rubocop'
23
- gem 'rubocop-performance'
24
- gem 'rubocop-rails'
25
- gem 'rubocop-rspec'
26
- end
27
- end
28
- end
29
- end
@@ -1,65 +0,0 @@
1
- # AuxiliaryRails RuboCop Config
2
- # Homepage: https://github.com/ergoserv/auxiliary_rails
3
- # Version: 8
4
-
5
- AllCops:
6
- Exclude:
7
- - 'bin/*'
8
- - 'db/schema.rb'
9
- - 'db/migrate/*'
10
- - 'node_modules/**/*'
11
- - 'vendor/**/*'
12
-
13
- #################### Layout ###############################
14
-
15
- Layout/AlignArguments:
16
- EnforcedStyle: with_fixed_indentation
17
-
18
- #################### Metrics ###############################
19
-
20
- Metrics/BlockLength:
21
- ExcludedMethods:
22
- - describe
23
- - resource
24
-
25
- Metrics/MethodLength:
26
- Max: 30
27
-
28
- #################### Naming ################################
29
-
30
- Naming/MemoizedInstanceVariableName:
31
- Exclude:
32
- - 'app/apis/**/resources/*_resource.rb'
33
-
34
- #################### Rails #################################
35
-
36
- Rails:
37
- Enabled: true
38
-
39
- #################### RSpec #################################
40
-
41
- RSpec/ExampleLength:
42
- Max: 10
43
-
44
- RSpec/NamedSubject:
45
- Enabled: false
46
-
47
- #################### Style #################################
48
-
49
- Style/Documentation:
50
- Enabled: false
51
-
52
- Style/FrozenStringLiteralComment:
53
- Enabled: false
54
-
55
- Style/IfUnlessModifier:
56
- Enabled: false
57
-
58
- Style/NegatedIf:
59
- EnforcedStyle: postfix
60
-
61
- Style/NumericPredicate:
62
- EnforcedStyle: comparison
63
-
64
- Style/RescueStandardError:
65
- EnforcedStyle: implicit
@@ -1,11 +0,0 @@
1
- inherit_from:
2
- - .rubocop_auxiliary_rails.yml
3
-
4
- inherit_mode:
5
- merge:
6
- - Exclude
7
-
8
- require:
9
- - rubocop-performance
10
- - rubocop-rails
11
- - rubocop-rspec