pragma-rails 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b813fe8cf53b4558b118cca550eb851dff77b9f4
4
- data.tar.gz: 7e675468e6837c1a63b4e8c957bf701232446b56
3
+ metadata.gz: 84f5e5aa2aaa165d80723c35f5f0ad2f94e4e18c
4
+ data.tar.gz: 27402000c2a1f980b0ea8edc6557b3415834d468
5
5
  SHA512:
6
- metadata.gz: 5a2a1055ba16a3bd8a7feb6a67a03af1a140d6470aa814a62677c5ef8b77fc598486d16eb17da2d0e6f44624dc7740a9c4610148526285c74bdb80fc6fc8a1a8
7
- data.tar.gz: 63dc8ac52215dab16588f3906ad9c0a9226a2ef481d7852fd82e640f0c9cba317e8888b9da62b28ccd56e3b0b6f12a7541f9d3b96d98966acabcebeb93c93955
6
+ metadata.gz: af7b4c4bf91ed7517c44abb04927888953e228f9c8c4c69c110afa93be69ab6754f505a722c26bc391b6f8c3170527066247bc61026a5f58c0412a9c5fc2c620
7
+ data.tar.gz: b4a1249b7a4452a332fb8ee7e450b34f90f899c0acf6fc04c19e1bdda03d1627d83724229b1c16aa5afd31123429a3deb647cc11d3f20a31869399ff8df79248
data/.rubocop.yml CHANGED
@@ -25,30 +25,30 @@ Style/BlockDelimiters:
25
25
  Exclude:
26
26
  - 'spec/**/*'
27
27
 
28
- Style/FileName:
28
+ Naming/FileName:
29
29
  Exclude:
30
30
  - 'pragma-rails.gemspec'
31
31
 
32
- Style/AlignParameters:
32
+ Layout/AlignParameters:
33
33
  EnforcedStyle: with_fixed_indentation
34
34
 
35
- Style/ClosingParenthesisIndentation:
35
+ Layout/ClosingParenthesisIndentation:
36
36
  Enabled: false
37
37
 
38
38
  Metrics/LineLength:
39
39
  Max: 100
40
40
  AllowURI: true
41
41
 
42
- Style/FirstParameterIndentation:
42
+ Layout/FirstParameterIndentation:
43
43
  Enabled: false
44
44
 
45
- Style/MultilineMethodCallIndentation:
45
+ Layout/MultilineMethodCallIndentation:
46
46
  EnforcedStyle: indented
47
47
 
48
- Style/IndentArray:
48
+ Layout/IndentArray:
49
49
  EnforcedStyle: consistent
50
50
 
51
- Style/IndentHash:
51
+ Layout/IndentHash:
52
52
  EnforcedStyle: consistent
53
53
 
54
54
  Style/SignalException:
@@ -73,7 +73,7 @@ RSpec/NamedSubject:
73
73
  RSpec/ExampleLength:
74
74
  Enabled: false
75
75
 
76
- Style/MultilineMethodCallBraceLayout:
76
+ Layout/MultilineMethodCallBraceLayout:
77
77
  Enabled: false
78
78
 
79
79
  Metrics/MethodLength:
@@ -99,3 +99,7 @@ RSpec/MessageExpectation:
99
99
 
100
100
  RSpec/MessageSpies:
101
101
  Enabled: false
102
+
103
+ RSpec/DescribeClass:
104
+ Exclude:
105
+ - 'spec/integration/**/*'
data/CHANGELOG.md ADDED
@@ -0,0 +1,30 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
6
+ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [2.1.0]
11
+
12
+ ### Added
13
+
14
+ - Implemented support for using the generators in mountable engines
15
+
16
+ ### Changed
17
+
18
+ - Replaced `feature` with `include` in generators and tests
19
+
20
+ ### Fixed
21
+
22
+ - Fixed edge cases in collection rendering for resources without a decorator
23
+
24
+ ## [2.0.0]
25
+
26
+ First Pragma 2 release.
27
+
28
+ [Unreleased]: https://github.com/pragmarb/pragma-rails/compare/v2.1.0...HEAD
29
+ [2.1.0]: https://github.com/pragmarb/pragma-rails/compare/v2.0.0...v2.1.0
30
+ [2.0.0]: https://github.com/pragmarb/pragma-rails/compare/v1.2.4...v2.0.0
data/Gemfile CHANGED
@@ -2,9 +2,3 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in pragma-rails.gemspec
4
4
  gemspec
5
-
6
- gem 'pragma', github: 'pragmarb/pragma'
7
- gem 'pragma-operation', github: 'pragmarb/pragma-operation'
8
- gem 'pragma-contract', github: 'pragmarb/pragma-contract'
9
- gem 'pragma-policy', github: 'pragmarb/pragma-policy'
10
- gem 'pragma-decorator', github: 'pragmarb/pragma-decorator'
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # Pragma on Rails
2
2
 
3
- [![Build Status](https://img.shields.io/travis/pragmarb/pragma-rails.svg?maxAge=3600&style=flat-square)](https://travis-ci.org/pragmarb/pragma-rails)
4
- [![Dependency Status](https://img.shields.io/gemnasium/pragmarb/pragma-rails.svg?maxAge=3600&style=flat-square)](https://gemnasium.com/github.com/pragmarb/pragma-rails)
5
- [![Code Climate](https://img.shields.io/codeclimate/github/pragmarb/pragma-rails.svg?maxAge=3600&style=flat-square)](https://codeclimate.com/github/pragmarb/pragma-rails)
6
- [![Coveralls](https://img.shields.io/coveralls/pragmarb/pragma-rails.svg?maxAge=3600&style=flat-square)](https://coveralls.io/github/pragmarb/pragma-rails)
3
+ [![Build Status](https://travis-ci.org/pragmarb/pragma-rails.svg?branch=master)](https://travis-ci.org/pragmarb/pragma-rails)
4
+ [![Dependency Status](https://gemnasium.com/badges/github.com/pragmarb/pragma-rails.svg)](https://gemnasium.com/github.com/pragmarb/pragma-rails)
5
+ [![Coverage Status](https://coveralls.io/repos/github/pragmarb/pragma-rails/badge.svg?branch=master)](https://coveralls.io/github/pragmarb/pragma-rails?branch=master)
6
+ [![Maintainability](https://api.codeclimate.com/v1/badges/e51e8d7489eb72ab97ba/maintainability)](https://codeclimate.com/github/pragmarb/pragma-rails/maintainability)
7
7
 
8
8
  This gem provides Ruby on Rails integration for the [Pragma](https://github.com/pragmarb/pragma) architecture.
9
9
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pragma
4
- class ResourceGenerator < ::Rails::Generators::NamedBase
4
+ class ResourceGenerator < ::Rails::Generators::NamedBase # :nodoc:
5
5
  source_root File.expand_path('../templates', __FILE__)
6
6
 
7
7
  class_option :version, type: :numeric, default: 1, desc: 'The API version to use', aliases: '-v'
@@ -15,25 +15,40 @@ module Pragma
15
15
 
16
16
  private
17
17
 
18
+ def namespaced_path
19
+ namespaced? ? super : ''
20
+ end
21
+
18
22
  def copy_resource_files
19
- directory 'resource/resource', "app/resources/api/v#{options['version']}/#{file_name}"
23
+ directory(
24
+ 'resource/resource',
25
+ "app/resources/#{namespaced_path}/api/v#{options['version']}/#{file_name}"
26
+ )
20
27
  end
21
28
 
22
29
  def copy_controller
23
- template 'resource/controller.rb', "app/controllers/api/v#{options['version']}/#{file_name.pluralize}_controller.rb"
30
+ # rubocop:disable Metrics/LineLength
31
+ template(
32
+ 'resource/controller.rb',
33
+ "app/controllers/#{namespaced_path}/api/v#{options['version']}/#{file_name.pluralize}_controller.rb"
34
+ )
35
+ # rubocop:enable Metrics/LineLength
24
36
  end
25
37
 
26
38
  def copy_spec
27
- template 'resource/spec.rb', "spec/requests/api/v#{options['version']}/#{file_name.pluralize}_spec.rb"
39
+ template(
40
+ 'resource/spec.rb',
41
+ "spec/requests/#{namespaced_path}/api/v#{options['version']}/#{file_name.pluralize}_spec.rb"
42
+ )
28
43
  end
29
44
 
30
- def class_path
45
+ def route_path
31
46
  ['api', "v#{options['version']}"]
32
47
  end
33
48
 
34
49
  # Taken from https://github.com/rails/rails/blob/master/railties/lib/rails/generators/rails/resource_route/resource_route_generator.rb
35
50
  def generate_route
36
- class_path.each_with_index do |namespace, index|
51
+ route_path.each_with_index do |namespace, index|
37
52
  write("namespace :#{namespace} do", index + 1)
38
53
  end
39
54
 
@@ -41,9 +56,14 @@ module Pragma
41
56
  ", path: '#{file_name.pluralize.tr('_', '-')}'"
42
57
  end
43
58
 
44
- write("resources :#{file_name.pluralize}, only: %i(index show create update destroy)#{path_fragment}", route_length + 1)
59
+ # rubocop:disable Metrics/LineLength
60
+ write(
61
+ "resources :#{file_name.pluralize}, only: %i(index show create update destroy)#{path_fragment}",
62
+ route_length + 1
63
+ )
64
+ # rubocop:enable Metrics/LineLength
45
65
 
46
- class_path.each_index do |index|
66
+ route_path.each_index do |index|
47
67
  write('end', route_length - index)
48
68
  end
49
69
 
@@ -62,7 +82,7 @@ module Pragma
62
82
  end
63
83
 
64
84
  def route_length
65
- class_path.length
85
+ route_path.length
66
86
  end
67
87
  end
68
88
  end
@@ -1,6 +1,8 @@
1
+ <% module_namespacing do -%>
1
2
  module API
2
3
  module V<%= options['version'] %>
3
4
  class <%= file_name.pluralize.camelcase %>Controller < ResourceController
4
5
  end
5
6
  end
6
7
  end
8
+ <% end -%>
@@ -1,3 +1,4 @@
1
+ <% module_namespacing do -%>
1
2
  module API
2
3
  module V<%= options['version'] %>
3
4
  module <%= file_name.camelcase %>
@@ -8,3 +9,4 @@ module API
8
9
  end
9
10
  end
10
11
  end
12
+ <% end -%>
@@ -1,3 +1,4 @@
1
+ <% module_namespacing do -%>
1
2
  module API
2
3
  module V<%= options['version'] %>
3
4
  module <%= file_name.camelcase %>
@@ -8,3 +9,4 @@ module API
8
9
  end
9
10
  end
10
11
  end
12
+ <% end -%>
@@ -1,3 +1,4 @@
1
+ <% module_namespacing do -%>
1
2
  module API
2
3
  module V<%= options['version'] %>
3
4
  module <%= file_name.camelcase %>
@@ -8,3 +9,4 @@ module API
8
9
  end
9
10
  end
10
11
  end
12
+ <% end -%>
@@ -1,11 +1,12 @@
1
+ <% module_namespacing do -%>
1
2
  module API
2
3
  module V<%= options['version'] %>
3
4
  module <%= file_name.camelcase %>
4
5
  module Decorator
5
6
  class Collection < Pragma::Decorator::Base
6
- feature Pragma::Decorator::Type
7
- feature Pragma::Decorator::Collection
8
- feature Pragma::Decorator::Pagination
7
+ include Pragma::Decorator::Type
8
+ include Pragma::Decorator::Collection
9
+ include Pragma::Decorator::Pagination
9
10
 
10
11
  decorate_with Instance
11
12
  end
@@ -13,3 +14,4 @@ module API
13
14
  end
14
15
  end
15
16
  end
17
+ <% end -%>
@@ -1,11 +1,13 @@
1
+ <% module_namespacing do -%>
1
2
  module API
2
3
  module V<%= options['version'] %>
3
4
  module <%= file_name.camelcase %>
4
5
  module Decorator
5
6
  class Instance < Pragma::Decorator::Base
6
- feature Pragma::Decorator::Type
7
+ include Pragma::Decorator::Type
7
8
  end
8
9
  end
9
10
  end
10
11
  end
11
12
  end
13
+ <% end -%>
@@ -1,3 +1,4 @@
1
+ <% module_namespacing do -%>
1
2
  module API
2
3
  module V<%= options['version'] %>
3
4
  module <%= file_name.camelcase %>
@@ -8,3 +9,4 @@ module API
8
9
  end
9
10
  end
10
11
  end
12
+ <% end -%>
@@ -1,3 +1,4 @@
1
+ <% module_namespacing do -%>
1
2
  module API
2
3
  module V<%= options['version'] %>
3
4
  module <%= file_name.camelcase %>
@@ -8,3 +9,4 @@ module API
8
9
  end
9
10
  end
10
11
  end
12
+ <% end -%>
@@ -1,3 +1,4 @@
1
+ <% module_namespacing do -%>
1
2
  module API
2
3
  module V<%= options['version'] %>
3
4
  module <%= file_name.camelcase %>
@@ -8,3 +9,4 @@ module API
8
9
  end
9
10
  end
10
11
  end
12
+ <% end -%>
@@ -1,3 +1,4 @@
1
+ <% module_namespacing do -%>
1
2
  module API
2
3
  module V<%= options['version'] %>
3
4
  module <%= file_name.camelcase %>
@@ -8,3 +9,4 @@ module API
8
9
  end
9
10
  end
10
11
  end
12
+ <% end -%>
@@ -1,3 +1,4 @@
1
+ <% module_namespacing do -%>
1
2
  module API
2
3
  module V<%= options['version'] %>
3
4
  module <%= file_name.camelcase %>
@@ -8,3 +9,4 @@ module API
8
9
  end
9
10
  end
10
11
  end
12
+ <% end -%>
@@ -1,3 +1,4 @@
1
+ <% module_namespacing do -%>
1
2
  module API
2
3
  module V<%= options['version'] %>
3
4
  module <%= file_name.camelcase %>
@@ -27,3 +28,4 @@ module API
27
28
  end
28
29
  end
29
30
  end
31
+ <% end -%>
@@ -34,10 +34,7 @@ module Pragma
34
34
  if result['result.response'].entity
35
35
  render(
36
36
  status: result['result.response'].status,
37
- json: result['result.response'].entity.to_json(user_options: {
38
- expand: params[:expand],
39
- current_user: operation_user
40
- })
37
+ json: entity_to_hash(result['result.response'].entity).as_json
41
38
  )
42
39
  else
43
40
  head result['result.response'].status
@@ -63,6 +60,25 @@ module Pragma
63
60
  def operation_user
64
61
  current_user if respond_to?(:current_user)
65
62
  end
63
+
64
+ private
65
+
66
+ def entity_to_hash(entity)
67
+ options = {
68
+ user_options: {
69
+ expand: params[:expand],
70
+ current_user: operation_user
71
+ }
72
+ }
73
+
74
+ if entity.is_a?(Array)
75
+ entity.map { |e| entity_to_hash(e) }
76
+ elsif entity.respond_to?(:to_hash)
77
+ entity.method(:to_hash).arity.zero? ? entity.to_hash : entity.to_hash(options)
78
+ else
79
+ entity.as_json(options)
80
+ end
81
+ end
66
82
  end
67
83
  end
68
84
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Pragma
4
4
  module Rails
5
- VERSION = '2.0.0'
5
+ VERSION = '2.1.0'
6
6
  end
7
7
  end
data/pragma-rails.gemspec CHANGED
@@ -25,15 +25,15 @@ Gem::Specification.new do |spec|
25
25
  spec.add_dependency 'rails', '>= 4.2', '< 6'
26
26
 
27
27
  spec.add_development_dependency 'bundler'
28
- spec.add_development_dependency 'rake'
29
- spec.add_development_dependency 'rspec-rails'
30
- spec.add_development_dependency 'rubocop'
31
- spec.add_development_dependency 'rubocop-rspec'
32
- spec.add_development_dependency 'coveralls'
33
28
  spec.add_development_dependency 'capybara'
34
- spec.add_development_dependency 'factory_girl_rails'
29
+ spec.add_development_dependency 'coveralls'
35
30
  spec.add_development_dependency 'database_cleaner'
31
+ spec.add_development_dependency 'factory_girl_rails'
36
32
  spec.add_development_dependency 'faker'
37
33
  spec.add_development_dependency 'pry-rails'
34
+ spec.add_development_dependency 'rake'
35
+ spec.add_development_dependency 'rspec-rails'
36
+ spec.add_development_dependency 'rubocop'
37
+ spec.add_development_dependency 'rubocop-rspec'
38
38
  spec.add_development_dependency 'sqlite3'
39
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pragma-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alessandro Desantis
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-27 00:00:00.000000000 Z
11
+ date: 2018-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pragma
@@ -59,7 +59,7 @@ dependencies:
59
59
  - !ruby/object:Gem::Version
60
60
  version: '0'
61
61
  - !ruby/object:Gem::Dependency
62
- name: rake
62
+ name: capybara
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
65
  - - ">="
@@ -73,7 +73,7 @@ dependencies:
73
73
  - !ruby/object:Gem::Version
74
74
  version: '0'
75
75
  - !ruby/object:Gem::Dependency
76
- name: rspec-rails
76
+ name: coveralls
77
77
  requirement: !ruby/object:Gem::Requirement
78
78
  requirements:
79
79
  - - ">="
@@ -87,7 +87,7 @@ dependencies:
87
87
  - !ruby/object:Gem::Version
88
88
  version: '0'
89
89
  - !ruby/object:Gem::Dependency
90
- name: rubocop
90
+ name: database_cleaner
91
91
  requirement: !ruby/object:Gem::Requirement
92
92
  requirements:
93
93
  - - ">="
@@ -101,7 +101,7 @@ dependencies:
101
101
  - !ruby/object:Gem::Version
102
102
  version: '0'
103
103
  - !ruby/object:Gem::Dependency
104
- name: rubocop-rspec
104
+ name: factory_girl_rails
105
105
  requirement: !ruby/object:Gem::Requirement
106
106
  requirements:
107
107
  - - ">="
@@ -115,7 +115,7 @@ dependencies:
115
115
  - !ruby/object:Gem::Version
116
116
  version: '0'
117
117
  - !ruby/object:Gem::Dependency
118
- name: coveralls
118
+ name: faker
119
119
  requirement: !ruby/object:Gem::Requirement
120
120
  requirements:
121
121
  - - ">="
@@ -129,7 +129,7 @@ dependencies:
129
129
  - !ruby/object:Gem::Version
130
130
  version: '0'
131
131
  - !ruby/object:Gem::Dependency
132
- name: capybara
132
+ name: pry-rails
133
133
  requirement: !ruby/object:Gem::Requirement
134
134
  requirements:
135
135
  - - ">="
@@ -143,7 +143,7 @@ dependencies:
143
143
  - !ruby/object:Gem::Version
144
144
  version: '0'
145
145
  - !ruby/object:Gem::Dependency
146
- name: factory_girl_rails
146
+ name: rake
147
147
  requirement: !ruby/object:Gem::Requirement
148
148
  requirements:
149
149
  - - ">="
@@ -157,7 +157,7 @@ dependencies:
157
157
  - !ruby/object:Gem::Version
158
158
  version: '0'
159
159
  - !ruby/object:Gem::Dependency
160
- name: database_cleaner
160
+ name: rspec-rails
161
161
  requirement: !ruby/object:Gem::Requirement
162
162
  requirements:
163
163
  - - ">="
@@ -171,7 +171,7 @@ dependencies:
171
171
  - !ruby/object:Gem::Version
172
172
  version: '0'
173
173
  - !ruby/object:Gem::Dependency
174
- name: faker
174
+ name: rubocop
175
175
  requirement: !ruby/object:Gem::Requirement
176
176
  requirements:
177
177
  - - ">="
@@ -185,7 +185,7 @@ dependencies:
185
185
  - !ruby/object:Gem::Version
186
186
  version: '0'
187
187
  - !ruby/object:Gem::Dependency
188
- name: pry-rails
188
+ name: rubocop-rspec
189
189
  requirement: !ruby/object:Gem::Requirement
190
190
  requirements:
191
191
  - - ">="
@@ -223,6 +223,7 @@ files:
223
223
  - ".rspec"
224
224
  - ".rubocop.yml"
225
225
  - ".travis.yml"
226
+ - CHANGELOG.md
226
227
  - Gemfile
227
228
  - LICENSE.txt
228
229
  - README.md