modulorails 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +239 -17
  4. data/Appraisals +6 -6
  5. data/CHANGELOG.md +19 -0
  6. data/app/helpers/modulorails/application_helper.rb +4 -2
  7. data/gemfiles/rails_52.gemfile +5 -5
  8. data/gemfiles/rails_60.gemfile +5 -5
  9. data/gemfiles/rails_61.gemfile +5 -5
  10. data/gemfiles/rails_70.gemfile +5 -5
  11. data/lib/generators/modulorails/docker/docker_generator.rb +10 -1
  12. data/lib/generators/modulorails/docker/templates/Dockerfile.prod.tt +4 -0
  13. data/lib/generators/modulorails/docker/templates/Dockerfile.tt +3 -0
  14. data/lib/generators/modulorails/docker/templates/config/database.yml.tt +1 -1
  15. data/lib/generators/modulorails/docker/templates/docker-compose.yml.tt +6 -1
  16. data/lib/generators/modulorails/docker/templates/entrypoints/docker-entrypoint.sh.tt +2 -2
  17. data/lib/generators/modulorails/gitlabci/gitlabci_generator.rb +4 -2
  18. data/lib/generators/modulorails/healthcheck/health_check_generator.rb +8 -5
  19. data/lib/generators/modulorails/rubocop/rubocop_generator.rb +8 -6
  20. data/lib/generators/modulorails/self_update/self_update_generator.rb +6 -3
  21. data/lib/generators/modulorails/service/service_generator.rb +3 -1
  22. data/lib/modulorails/configuration.rb +4 -0
  23. data/lib/modulorails/data.rb +113 -62
  24. data/lib/modulorails/error_data.rb +2 -0
  25. data/lib/modulorails/errors/invalid_format_error.rb +2 -0
  26. data/lib/modulorails/errors/invalid_value_error.rb +2 -0
  27. data/lib/modulorails/railtie.rb +5 -1
  28. data/lib/modulorails/services/base_service.rb +20 -18
  29. data/lib/modulorails/services/logs_for_method_service.rb +1 -0
  30. data/lib/modulorails/success_data.rb +2 -0
  31. data/lib/modulorails/validators/database_configuration.rb +19 -9
  32. data/lib/modulorails/version.rb +3 -1
  33. data/lib/modulorails.rb +40 -33
  34. data/modulorails.gemspec +8 -7
  35. metadata +32 -33
  36. data/lib/generators/modulorails/gitlabci/templates/config/database-ci.yml.tt +0 -8
data/lib/modulorails.rb CHANGED
@@ -17,11 +17,13 @@ require 'modulorails/services/services'
17
17
  # The entry point of the gem. It exposes the configurator, the gathered data and the method to
18
18
  # send those data to the intranet.
19
19
  module Modulorails
20
+
20
21
  # Author: Matthieu 'ciappa_m' Ciappara
21
22
  # The error class of the gem. Allow to identify all functional errors raised by the gem.
22
23
  class Error < StandardError; end
23
24
 
24
25
  class << self
26
+
25
27
  # Useful to update the configuration
26
28
  attr_writer :configuration
27
29
 
@@ -73,38 +75,38 @@ module Modulorails
73
75
  # If no endpoint and/or no API key is configured, it is impossible to send the data to the
74
76
  # intranet and thus we raise an error: it is the only error we want to raise since it goes
75
77
  # against one of the main goals of the gem and the gem's user is responsible.
76
- if configuration.endpoint && configuration.api_key
77
- # Define the headers of the request ; sending JSON and API key to authenticate the gem on
78
- # the intranet
79
- headers = {
80
- 'Content-Type' => 'application/json', 'X-MODULORAILS-TOKEN' => configuration.api_key
81
- }
82
-
83
- # Define the JSON body of the request
84
- body = data.to_params.to_json
85
-
86
- # Prevent HTTParty to raise error and crash the server in dev
87
- begin
88
- # Post to the configured endpoint on the Intranet
89
- response = HTTParty.post(configuration.endpoint, headers: headers, body: body)
90
-
91
- # According to the API specification, on a "Bad request" response, the server explicits what
92
- # went wrong with an `errors` field. We do not want to raise since the gem's user is not
93
- # (necessarily) responsible for the error but we still need to display it somewhere to warn
94
- # the user something went wrong.
95
- puts("[Modulorails] Error: #{response['errors'].join(', ')}") if response.code == 400
96
-
97
- # Return the response to allow users to do some more
98
- response
99
- rescue StandardError => e
100
- # Still need to notify the user
101
- puts("[Modulorails] Error: Could not post to #{configuration.endpoint}")
102
- puts e.message
103
- nil
104
- end
105
- else
78
+ unless configuration.endpoint && configuration.api_key
106
79
  raise Error.new('No endpoint or api key')
107
80
  end
81
+
82
+ # Define the headers of the request ; sending JSON and API key to authenticate the gem on
83
+ # the intranet
84
+ headers = {
85
+ 'Content-Type' => 'application/json', 'X-MODULORAILS-TOKEN' => configuration.api_key
86
+ }
87
+
88
+ # Define the JSON body of the request
89
+ body = data.to_params.to_json
90
+
91
+ # Prevent HTTParty to raise error and crash the server in dev
92
+ begin
93
+ # Post to the configured endpoint on the Intranet
94
+ response = HTTParty.post(configuration.endpoint, headers: headers, body: body)
95
+
96
+ # According to the API specification, on a "Bad request" response, the server explicits what
97
+ # went wrong with an `errors` field. We do not want to raise since the gem's user is not
98
+ # (necessarily) responsible for the error but we still need to display it somewhere to warn
99
+ # the user something went wrong.
100
+ puts("[Modulorails] Error: #{response['errors'].join(', ')}") if response.code == 400
101
+
102
+ # Return the response to allow users to do some more
103
+ response
104
+ rescue StandardError => e
105
+ # Still need to notify the user
106
+ puts("[Modulorails] Error: Could not post to #{configuration.endpoint}")
107
+ puts e.message
108
+ nil
109
+ end
108
110
  end
109
111
 
110
112
  # @author Matthieu 'ciappa_m' Ciappara
@@ -112,7 +114,7 @@ module Modulorails
112
114
  # Generate a CI/CD template unless it was already done.
113
115
  # The check is done using a 'keepfile'.
114
116
  def generate_ci_template
115
- return if File.exists?(Rails.root.join('.modulorails-gitlab-ci'))
117
+ return if File.exist?(Rails.root.join('.modulorails-gitlab-ci'))
116
118
 
117
119
  Modulorails::GitlabciGenerator.new([], {}, {}).invoke_all
118
120
  end
@@ -138,7 +140,10 @@ module Modulorails
138
140
  # Check the last version of Modulorails available on rubygems and update if there was a
139
141
  # publication
140
142
  def self_update
141
- Modulorails::SelfUpdateGenerator.new([], {}, {}).invoke_all unless configuration.no_auto_update
143
+ unless configuration.no_auto_update
144
+ Modulorails::SelfUpdateGenerator.new([], {},
145
+ {}).invoke_all
146
+ end
142
147
  rescue StandardError => e
143
148
  puts("[Modulorails] An error occured: #{e.class} - #{e.message}")
144
149
  end
@@ -148,7 +153,7 @@ module Modulorails
148
153
  # Generate a health_check configuration unless it was already done.
149
154
  # The check is done using a 'keepfile'.
150
155
  def generate_healthcheck_template
151
- return if File.exists?(Rails.root.join('.modulorails-health_check'))
156
+ return if File.exist?(Rails.root.join('.modulorails-health_check'))
152
157
 
153
158
  Modulorails::HealthCheckGenerator.new([], {}, {}).invoke_all
154
159
  end
@@ -159,5 +164,7 @@ module Modulorails
159
164
  def generate_rubocop_template
160
165
  Modulorails::RubocopGenerator.new([], {}, {}).invoke_all
161
166
  end
167
+
162
168
  end
169
+
163
170
  end
data/modulorails.gemspec CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
7
7
  spec.email = ['ciappa_m@modulotech.fr']
8
8
 
9
9
  spec.summary = 'Common base for Ruby on Rails projects at Modulotech'
10
- spec.description =<<~END_OF_TEXT
10
+ spec.description = <<~END_OF_TEXT
11
11
  Modulorails is the common base for the Ruby on Rails project at Modulotech
12
12
  (https://www.modulotech.fr/).
13
13
 
@@ -24,19 +24,20 @@ Gem::Specification.new do |spec|
24
24
 
25
25
  # Specify which files should be added to the gem when it is released.
26
26
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
27
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
27
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
28
28
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
29
29
  end
30
30
  spec.require_paths = ['lib']
31
31
 
32
- spec.add_runtime_dependency 'railties', '>= 4.2.0'
33
32
  spec.add_runtime_dependency 'git', '~> 1.7', '>= 1.7.0'
34
- spec.add_runtime_dependency 'httparty'
35
- spec.add_runtime_dependency 'i18n'
36
33
  spec.add_runtime_dependency 'health_check', '~> 3.1'
37
- spec.add_runtime_dependency 'rubocop', '= 1.25.1'
38
- spec.add_runtime_dependency 'rubocop-rails', '= 2.13.2'
34
+ spec.add_runtime_dependency 'httparty', '>= 0.13.3'
35
+ spec.add_runtime_dependency 'i18n', '>= 0.9.5'
36
+ spec.add_runtime_dependency 'railties', '>= 4.2.0'
37
+ spec.add_runtime_dependency 'rubocop', '>= 1.28.2'
38
+ spec.add_runtime_dependency 'rubocop-rails', '>= 2.14.2'
39
39
 
40
40
  spec.add_development_dependency 'activerecord', '>= 4.2.0'
41
41
  spec.add_development_dependency 'appraisal'
42
+ # spec.metadata['rubygems_mfa_required'] = 'true'
42
43
  end
metadata CHANGED
@@ -1,119 +1,119 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: modulorails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthieu Ciappara
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-10 00:00:00.000000000 Z
11
+ date: 2022-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: railties
14
+ name: git
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 4.2.0
19
+ version: 1.7.0
20
+ - - "~>"
21
+ - !ruby/object:Gem::Version
22
+ version: '1.7'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
27
  - - ">="
25
28
  - !ruby/object:Gem::Version
26
- version: 4.2.0
29
+ version: 1.7.0
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '1.7'
27
33
  - !ruby/object:Gem::Dependency
28
- name: git
34
+ name: health_check
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: 1.7.0
34
37
  - - "~>"
35
38
  - !ruby/object:Gem::Version
36
- version: '1.7'
39
+ version: '3.1'
37
40
  type: :runtime
38
41
  prerelease: false
39
42
  version_requirements: !ruby/object:Gem::Requirement
40
43
  requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- version: 1.7.0
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: '1.7'
46
+ version: '3.1'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: httparty
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - ">="
52
52
  - !ruby/object:Gem::Version
53
- version: '0'
53
+ version: 0.13.3
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - ">="
59
59
  - !ruby/object:Gem::Version
60
- version: '0'
60
+ version: 0.13.3
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: i18n
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
65
  - - ">="
66
66
  - !ruby/object:Gem::Version
67
- version: '0'
67
+ version: 0.9.5
68
68
  type: :runtime
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - ">="
73
73
  - !ruby/object:Gem::Version
74
- version: '0'
74
+ version: 0.9.5
75
75
  - !ruby/object:Gem::Dependency
76
- name: health_check
76
+ name: railties
77
77
  requirement: !ruby/object:Gem::Requirement
78
78
  requirements:
79
- - - "~>"
79
+ - - ">="
80
80
  - !ruby/object:Gem::Version
81
- version: '3.1'
81
+ version: 4.2.0
82
82
  type: :runtime
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
- - - "~>"
86
+ - - ">="
87
87
  - !ruby/object:Gem::Version
88
- version: '3.1'
88
+ version: 4.2.0
89
89
  - !ruby/object:Gem::Dependency
90
90
  name: rubocop
91
91
  requirement: !ruby/object:Gem::Requirement
92
92
  requirements:
93
- - - '='
93
+ - - ">="
94
94
  - !ruby/object:Gem::Version
95
- version: 1.25.1
95
+ version: 1.28.2
96
96
  type: :runtime
97
97
  prerelease: false
98
98
  version_requirements: !ruby/object:Gem::Requirement
99
99
  requirements:
100
- - - '='
100
+ - - ">="
101
101
  - !ruby/object:Gem::Version
102
- version: 1.25.1
102
+ version: 1.28.2
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: rubocop-rails
105
105
  requirement: !ruby/object:Gem::Requirement
106
106
  requirements:
107
- - - '='
107
+ - - ">="
108
108
  - !ruby/object:Gem::Version
109
- version: 2.13.2
109
+ version: 2.14.2
110
110
  type: :runtime
111
111
  prerelease: false
112
112
  version_requirements: !ruby/object:Gem::Requirement
113
113
  requirements:
114
- - - '='
114
+ - - ">="
115
115
  - !ruby/object:Gem::Version
116
- version: 2.13.2
116
+ version: 2.14.2
117
117
  - !ruby/object:Gem::Dependency
118
118
  name: activerecord
119
119
  requirement: !ruby/object:Gem::Requirement
@@ -195,7 +195,6 @@ files:
195
195
  - lib/generators/modulorails/gitlabci/gitlabci_generator.rb
196
196
  - lib/generators/modulorails/gitlabci/templates/.gitlab-ci.yml.tt
197
197
  - lib/generators/modulorails/gitlabci/templates/.modulorails-gitlab-ci
198
- - lib/generators/modulorails/gitlabci/templates/config/database-ci.yml.tt
199
198
  - lib/generators/modulorails/healthcheck/health_check_generator.rb
200
199
  - lib/generators/modulorails/healthcheck/templates/.modulorails-health_check
201
200
  - lib/generators/modulorails/healthcheck/templates/config/initializers/health_check.rb.tt
@@ -242,7 +241,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
242
241
  - !ruby/object:Gem::Version
243
242
  version: '0'
244
243
  requirements: []
245
- rubygems_version: 3.0.3
244
+ rubygems_version: 3.0.3.1
246
245
  signing_key:
247
246
  specification_version: 4
248
247
  summary: Common base for Ruby on Rails projects at Modulotech
@@ -1,8 +0,0 @@
1
- <%- adapter = Modulorails.data.adapter -%>
2
- test:
3
- host: <%= adapter =~ /mysql/ ? 'mysql' : 'postgres' %>
4
- adapter: <%= adapter %>
5
- database: test
6
- username: root
7
- password: password
8
- encoding: utf8