auxiliary_rails 0.1.7 → 0.1.8
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/Gemfile.lock +1 -1
- data/README.md +5 -2
- data/lib/auxiliary_rails/version.rb +1 -1
- data/lib/generators/auxiliary_rails/api_resource_generator.rb +10 -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/rubocop/rubocop_auxiliary_rails_template.yml +15 -1
- data/lib/generators/auxiliary_rails/templates/rubocop/rubocop_template.yml +4 -0
- data/templates/rails/elementary.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55024b258096ba35ea6d1ae4279ee9193d8c127d96186f86c91842b5436e7745
|
4
|
+
data.tar.gz: dccf5c0d9d4de4776af52ef0b55a3ca7b78debf1077019f55483e034df290753
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98e16100b8ac8cf42af60dfbd6ee79ef906f2537cce8170c1cd14eff4bda1890757f6b44d14b69140924541c4366b6f85b4d7063d7752add414583bf3134cd3d
|
7
|
+
data.tar.gz: 05e38836a6ed91b0df116239d0f3643c59615dc7ff074f7cfbedc15408a7e774dacc97f877a703ae82f4f6ed41f4b8588e9df6c18c2eef14255e37bdb46a6a16
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -46,14 +46,17 @@ rails new APP_PATH --skip-action-cable --skip-coffee --skip-test --database=post
|
|
46
46
|
### Generators
|
47
47
|
|
48
48
|
```sh
|
49
|
-
#
|
49
|
+
# Install everything at once
|
50
50
|
rails generate auxiliary_rails:install
|
51
51
|
|
52
|
-
#
|
52
|
+
# Install one by one
|
53
53
|
rails generate auxiliary_rails:install_commands
|
54
54
|
rails generate auxiliary_rails:install_errors
|
55
55
|
rails generate auxiliary_rails:install_rubocop
|
56
56
|
rails generate auxiliary_rails:install_rubocop --no-specify-gems
|
57
|
+
|
58
|
+
# API resource generator
|
59
|
+
rails generate auxiliary_rails:api_resource NAME
|
57
60
|
```
|
58
61
|
|
59
62
|
### View Helpers
|
@@ -37,7 +37,12 @@ module AuxiliaryRails
|
|
37
37
|
|
38
38
|
def create_api_resource_spec_file
|
39
39
|
template 'api_resource_spec_template.rb.erb',
|
40
|
-
"spec/#{api_module_path}/#{plural_file_name}_resource_spec.rb"
|
40
|
+
"spec/#{api_module_path}/resources/#{plural_file_name}_resource_spec.rb"
|
41
|
+
end
|
42
|
+
|
43
|
+
def say_instructions
|
44
|
+
say "Mount resource in #{api_module_name}:"
|
45
|
+
say " mount #{resource_class_name}"
|
41
46
|
end
|
42
47
|
|
43
48
|
private
|
@@ -59,5 +64,9 @@ module AuxiliaryRails
|
|
59
64
|
def entity_class_name
|
60
65
|
"#{api_module_name}::Entities::#{class_name}Entity"
|
61
66
|
end
|
67
|
+
|
68
|
+
def resource_class_name
|
69
|
+
"#{api_module_name}::Resources::#{plural_name.camelize}Resource"
|
70
|
+
end
|
62
71
|
end
|
63
72
|
end
|
@@ -1,11 +1,18 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
|
-
RSpec.describe <%=
|
3
|
+
RSpec.describe <%= resource_class_name %>, type: :request do
|
4
4
|
describe 'GET <%= api_url_path %>' do
|
5
5
|
subject { get '<%= api_url_path %>' }
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
it 'returns a list of <%= plural_name %>' do
|
8
|
+
create_list(:<%= singular_name %>, 2)
|
9
|
+
|
10
|
+
subject
|
11
|
+
|
12
|
+
expect_status :ok
|
13
|
+
expect_json_sizes 2
|
14
|
+
expect_json '0', id: <%= class_name %> %>.first.id
|
15
|
+
end
|
9
16
|
end
|
10
17
|
|
11
18
|
describe 'POST <%= api_url_path %>' do
|
@@ -16,17 +23,37 @@ RSpec.describe <%= api_module_name %>::Resources::<%= plural_name.camelize %>Res
|
|
16
23
|
end
|
17
24
|
|
18
25
|
describe 'GET <%= api_url_path %>/:id' do
|
19
|
-
|
20
|
-
|
26
|
+
subject { get "<%= api_url_path %>/#{<%= singular_name %>.id}" }
|
27
|
+
|
28
|
+
let(:<%= singular_name %>) { create(:<%= singular_name %>) }
|
29
|
+
|
30
|
+
it 'returns a <%= singular_name %> by ID' do
|
31
|
+
subject
|
32
|
+
|
33
|
+
expect_status :ok
|
34
|
+
expect_json id: <%= singular_name %>.id
|
35
|
+
end
|
21
36
|
end
|
22
37
|
|
23
38
|
describe 'PUT <%= api_url_path %>/:id' do
|
24
|
-
|
25
|
-
|
39
|
+
subject { put "<%= api_url_path %>/#{<%= singular_name %>.id}" }
|
40
|
+
|
41
|
+
let(:<%= singular_name %>) { create(:<%= singular_name %>) }
|
42
|
+
|
43
|
+
it 'updates a <%= singular_name %> by ID' do
|
44
|
+
skip
|
45
|
+
end
|
26
46
|
end
|
27
47
|
|
28
48
|
describe 'DELETE <%= api_url_path %>/:id' do
|
29
|
-
|
30
|
-
|
49
|
+
subject { delete "<%= api_url_path %>/#{<%= singular_name %>.id}" }
|
50
|
+
|
51
|
+
let!(:<%= singular_name %>) { create(:<%= singular_name %>) }
|
52
|
+
|
53
|
+
it 'deletes a <%= singular_name %> by ID' do
|
54
|
+
expect { subject }.to change(<%= class_name %>, :count).by -1
|
55
|
+
expect_status 204
|
56
|
+
expect(response.body).to be_blank
|
57
|
+
end
|
31
58
|
end
|
32
59
|
end
|
@@ -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,6 +1,6 @@
|
|
1
1
|
# AuxiliaryRails RuboCop Config
|
2
2
|
# Homepage: https://github.com/ergoserv/auxiliary_rails
|
3
|
-
# Version:
|
3
|
+
# Version: 8
|
4
4
|
|
5
5
|
AllCops:
|
6
6
|
Exclude:
|
@@ -17,9 +17,20 @@ Layout/AlignArguments:
|
|
17
17
|
|
18
18
|
#################### Metrics ###############################
|
19
19
|
|
20
|
+
Metrics/BlockLength:
|
21
|
+
ExcludedMethods:
|
22
|
+
- describe
|
23
|
+
- resource
|
24
|
+
|
20
25
|
Metrics/MethodLength:
|
21
26
|
Max: 30
|
22
27
|
|
28
|
+
#################### Naming ################################
|
29
|
+
|
30
|
+
Naming/MemoizedInstanceVariableName:
|
31
|
+
Exclude:
|
32
|
+
- 'app/apis/**/resources/*_resource.rb'
|
33
|
+
|
23
34
|
#################### Rails #################################
|
24
35
|
|
25
36
|
Rails:
|
@@ -27,6 +38,9 @@ Rails:
|
|
27
38
|
|
28
39
|
#################### RSpec #################################
|
29
40
|
|
41
|
+
RSpec/ExampleLength:
|
42
|
+
Max: 10
|
43
|
+
|
30
44
|
RSpec/NamedSubject:
|
31
45
|
Enabled: false
|
32
46
|
|
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.1.8
|
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: 2019-
|
12
|
+
date: 2019-09-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|