modulorails 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +239 -17
- data/Appraisals +6 -6
- data/CHANGELOG.md +19 -0
- data/app/helpers/modulorails/application_helper.rb +4 -2
- data/gemfiles/rails_52.gemfile +5 -5
- data/gemfiles/rails_60.gemfile +5 -5
- data/gemfiles/rails_61.gemfile +5 -5
- data/gemfiles/rails_70.gemfile +5 -5
- data/lib/generators/modulorails/docker/docker_generator.rb +10 -1
- data/lib/generators/modulorails/docker/templates/Dockerfile.prod.tt +4 -0
- data/lib/generators/modulorails/docker/templates/Dockerfile.tt +3 -0
- data/lib/generators/modulorails/docker/templates/config/database.yml.tt +1 -1
- data/lib/generators/modulorails/docker/templates/docker-compose.yml.tt +6 -1
- data/lib/generators/modulorails/docker/templates/entrypoints/docker-entrypoint.sh.tt +2 -2
- data/lib/generators/modulorails/gitlabci/gitlabci_generator.rb +4 -2
- data/lib/generators/modulorails/healthcheck/health_check_generator.rb +8 -5
- data/lib/generators/modulorails/rubocop/rubocop_generator.rb +8 -6
- data/lib/generators/modulorails/self_update/self_update_generator.rb +6 -3
- data/lib/generators/modulorails/service/service_generator.rb +3 -1
- data/lib/modulorails/configuration.rb +4 -0
- data/lib/modulorails/data.rb +113 -62
- data/lib/modulorails/error_data.rb +2 -0
- data/lib/modulorails/errors/invalid_format_error.rb +2 -0
- data/lib/modulorails/errors/invalid_value_error.rb +2 -0
- data/lib/modulorails/railtie.rb +5 -1
- data/lib/modulorails/services/base_service.rb +20 -18
- data/lib/modulorails/services/logs_for_method_service.rb +1 -0
- data/lib/modulorails/success_data.rb +2 -0
- data/lib/modulorails/validators/database_configuration.rb +19 -9
- data/lib/modulorails/version.rb +3 -1
- data/lib/modulorails.rb +40 -33
- data/modulorails.gemspec +8 -7
- metadata +32 -33
- data/lib/generators/modulorails/gitlabci/templates/config/database-ci.yml.tt +0 -8
@@ -3,11 +3,13 @@
|
|
3
3
|
require 'rails/generators'
|
4
4
|
|
5
5
|
class Modulorails::ServiceGenerator < Rails::Generators::NamedBase
|
6
|
+
|
6
7
|
source_root File.expand_path('templates', __dir__)
|
7
8
|
desc 'This generator creates a service inheriting Modulorails::BaseService'
|
8
9
|
argument :arguments, type: :array, default: [], banner: 'argument argument'
|
9
10
|
|
10
11
|
def create_service_files
|
11
|
-
template
|
12
|
+
template 'service.rb', File.join('app/services', class_path, "#{file_name}_service.rb")
|
12
13
|
end
|
14
|
+
|
13
15
|
end
|
@@ -1,7 +1,9 @@
|
|
1
1
|
module Modulorails
|
2
|
+
|
2
3
|
# Author: Matthieu 'ciappa_m' Ciappara
|
3
4
|
# The configuration of the gem
|
4
5
|
class Configuration
|
6
|
+
|
5
7
|
# All the keys to configure the gem
|
6
8
|
attr_accessor :_name, :_main_developer, :_project_manager, :_endpoint, :_api_key,
|
7
9
|
:_no_auto_update, :_production_url, :_staging_url, :_review_base_url
|
@@ -30,5 +32,7 @@ module Modulorails
|
|
30
32
|
send("_#{field}=", value)
|
31
33
|
end
|
32
34
|
end
|
35
|
+
|
33
36
|
end
|
37
|
+
|
34
38
|
end
|
data/lib/modulorails/data.rb
CHANGED
@@ -3,47 +3,90 @@ require 'active_record'
|
|
3
3
|
require 'git'
|
4
4
|
|
5
5
|
module Modulorails
|
6
|
+
|
6
7
|
# Author: Matthieu 'ciappa_m' Ciappara
|
7
8
|
# This holds the data gathered by the gem. Some come from the configuration by the gem's user.
|
8
9
|
# Some are fetched dynamically.
|
9
10
|
class Data
|
11
|
+
|
10
12
|
# All the data handled by this class
|
11
13
|
ATTRIBUTE_KEYS = %i[
|
12
14
|
name main_developer project_manager repository type rails_name ruby_version rails_version
|
13
|
-
bundler_version modulorails_version adapter db_version adapter_version
|
14
|
-
|
15
|
+
bundler_version modulorails_version adapter db_version adapter_version webpacker_version
|
16
|
+
importmap_version jsbundling_version
|
17
|
+
production_url staging_url review_base_url
|
15
18
|
].freeze
|
16
19
|
|
17
20
|
# Useful if the gem's user need to read one of the data
|
18
|
-
attr_reader
|
21
|
+
attr_reader(*ATTRIBUTE_KEYS)
|
19
22
|
|
20
23
|
def initialize
|
24
|
+
initialize_from_constants
|
25
|
+
initialize_from_configuration
|
26
|
+
initialize_from_database
|
27
|
+
initialize_from_gem_specs
|
28
|
+
initialize_from_git
|
29
|
+
end
|
30
|
+
|
31
|
+
# @author Matthieu 'ciappa_m' Ciappara
|
32
|
+
# @return [String] Text version of the data
|
33
|
+
def to_s
|
34
|
+
ATTRIBUTE_KEYS.map { |key| "#{key}: #{send(key)}" }.join(', ')
|
35
|
+
end
|
36
|
+
|
37
|
+
# @author Matthieu 'ciappa_m' Ciappara
|
38
|
+
# @return [Hash] The payload for the request to the intranet
|
39
|
+
def to_params
|
40
|
+
{
|
41
|
+
'name' => @name,
|
42
|
+
'main_developer' => @main_developer,
|
43
|
+
'project_manager' => @project_manager,
|
44
|
+
'repository' => @repository,
|
45
|
+
'app_type' => @type,
|
46
|
+
'project_data' => to_project_data_params
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def initialize_from_constants
|
53
|
+
# The API can handle more project types but this gem is (obviously) intended for Rails
|
54
|
+
# projects only
|
55
|
+
@type = 'rails'
|
56
|
+
|
57
|
+
# The name defined for the Rails application; it can be completely different from the usual
|
58
|
+
# name or can be the same
|
59
|
+
@rails_name = ::Rails.application.class.name&.split('::')&.first
|
60
|
+
|
61
|
+
# The Ruby version used by the application
|
62
|
+
@ruby_version = RUBY_VERSION
|
63
|
+
|
64
|
+
# The version of the gem
|
65
|
+
@modulorails_version = Modulorails::VERSION
|
66
|
+
end
|
67
|
+
|
68
|
+
def initialize_from_configuration
|
21
69
|
# Get the gem's configuration to get the application's usual name, main dev and PM
|
22
70
|
configuration = Modulorails.configuration
|
23
|
-
# Get the database connection to identify the database used by the application
|
24
|
-
# or return nil if the database does not exist
|
25
|
-
db_connection = begin
|
26
|
-
ActiveRecord::Base.connection
|
27
|
-
rescue ActiveRecord::NoDatabaseError => e
|
28
|
-
$stderr.puts("[Modulorails] Error: #{e.message}")
|
29
|
-
nil
|
30
|
-
end
|
31
|
-
# Get the gem's specifications to fetch the versions of critical gems
|
32
|
-
loaded_specs = Gem.loaded_specs
|
33
71
|
|
34
72
|
# The data written by the user in the configuration
|
35
73
|
# The name is the usual name of the project, the one used in conversations at Modulotech
|
36
74
|
@name = configuration.name
|
75
|
+
|
37
76
|
# The main developer, the lead developer, in short the developer to call when something's
|
38
77
|
# wrong with the application ;)
|
39
78
|
@main_developer = configuration.main_developer
|
79
|
+
|
40
80
|
# The project manager of the application; the other person to call when something's wrong with
|
41
81
|
# the application ;)
|
42
82
|
@project_manager = configuration.project_manager
|
83
|
+
|
43
84
|
# The URL of the production environment for the application
|
44
85
|
@production_url = configuration.production_url
|
86
|
+
|
45
87
|
# The URL of the staging environment for the application
|
46
88
|
@staging_url = configuration.staging_url
|
89
|
+
|
47
90
|
# The base URL of the review environment for the application.
|
48
91
|
# A real review URL is built like this at Modulotech:
|
49
92
|
# https://review-#{shortened_branch_name}-#{ci_slug}.#{review_base_url}
|
@@ -53,21 +96,29 @@ module Modulorails
|
|
53
96
|
# ci_slug: jzzham
|
54
97
|
# |-> https://review-786-a_sup-jzzham.dev.app.com/
|
55
98
|
@review_base_url = configuration.review_base_url
|
99
|
+
end
|
56
100
|
|
57
|
-
|
58
|
-
#
|
59
|
-
|
101
|
+
def initialize_from_database
|
102
|
+
# Get the database connection to identify the database used by the application
|
103
|
+
# or return nil if the database does not exist
|
104
|
+
db_connection = begin
|
105
|
+
ActiveRecord::Base.connection
|
106
|
+
rescue ActiveRecord::NoDatabaseError, ActiveRecord::ConnectionNotEstablished => e
|
107
|
+
warn("[Modulorails] Error: #{e.message}")
|
108
|
+
nil
|
109
|
+
end
|
60
110
|
|
61
|
-
# The
|
62
|
-
|
63
|
-
@type = 'rails'
|
111
|
+
# The name of the ActiveRecord adapter; it gives the name of the database system too
|
112
|
+
@adapter = db_connection&.adapter_name&.downcase
|
64
113
|
|
65
|
-
# The
|
66
|
-
#
|
67
|
-
@
|
114
|
+
# The version of the database engine; this request works only on MySQL and PostgreSQL
|
115
|
+
# It should not be a problem since those are the sole database engines used at Modulotech
|
116
|
+
@db_version = db_connection&.select_value('SELECT version()')
|
117
|
+
end
|
68
118
|
|
69
|
-
|
70
|
-
|
119
|
+
def initialize_from_gem_specs
|
120
|
+
# Get the gem's specifications to fetch the versions of critical gems
|
121
|
+
loaded_specs = Gem.loaded_specs
|
71
122
|
|
72
123
|
# The Rails version used by the application
|
73
124
|
@rails_version = loaded_specs['rails'].version.version
|
@@ -76,53 +127,53 @@ module Modulorails
|
|
76
127
|
# Bundler 1 are not compatible)
|
77
128
|
@bundler_version = loaded_specs['bundler'].version.version
|
78
129
|
|
79
|
-
# The version of the
|
80
|
-
@
|
130
|
+
# The version of the ActiveRecord adapter
|
131
|
+
@adapter_version = loaded_specs[@adapter]&.version&.version
|
81
132
|
|
82
|
-
# The
|
83
|
-
@
|
133
|
+
# The version of the webpacker gem - might be nil
|
134
|
+
@webpacker_version = loaded_specs['webpacker']&.version&.version
|
84
135
|
|
85
|
-
# The version of the
|
86
|
-
|
87
|
-
@db_version = db_connection&.select_value('SELECT version()')
|
136
|
+
# The version of the importmap-rails gem - might be nil
|
137
|
+
@importmap_version = loaded_specs['importmap-rails']&.version&.version
|
88
138
|
|
89
|
-
# The version of the
|
90
|
-
@
|
139
|
+
# The version of the jsbundling-rails gem - might be nil
|
140
|
+
@jsbundling_version = loaded_specs['jsbundling-rails']&.version&.version
|
91
141
|
end
|
92
142
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
143
|
+
def initialize_from_git
|
144
|
+
# Theorically, origin is the main repository of the project and git is the sole VCS we use
|
145
|
+
# at Modulotech
|
146
|
+
@repository = Git.open(::Rails.root).config('remote.origin.url')
|
97
147
|
end
|
98
148
|
|
99
|
-
|
100
|
-
# @return [Hash] The payload for the request to the intranet
|
101
|
-
def to_params
|
149
|
+
def to_project_data_params
|
102
150
|
{
|
103
|
-
'name'
|
104
|
-
'
|
105
|
-
'
|
106
|
-
'
|
107
|
-
'
|
108
|
-
'
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
},
|
119
|
-
'urls' => {
|
120
|
-
'production' => @production_url,
|
121
|
-
'staging' => @staging_url,
|
122
|
-
'review_base' => @review_base_url
|
123
|
-
}
|
124
|
-
}
|
151
|
+
'name' => @rails_name,
|
152
|
+
'ruby_version' => @ruby_version,
|
153
|
+
'rails_version' => @rails_version,
|
154
|
+
'bundler_version' => @bundler_version,
|
155
|
+
'modulorails_version' => @modulorails_version,
|
156
|
+
'database' => to_database_params,
|
157
|
+
'urls' => to_urls_params
|
158
|
+
}
|
159
|
+
end
|
160
|
+
|
161
|
+
def to_database_params
|
162
|
+
{
|
163
|
+
'adapter' => @adapter,
|
164
|
+
'db_version' => @db_version,
|
165
|
+
'gem_version' => @adapter_version
|
125
166
|
}
|
126
167
|
end
|
168
|
+
|
169
|
+
def to_urls_params
|
170
|
+
{
|
171
|
+
'production' => @production_url,
|
172
|
+
'staging' => @staging_url,
|
173
|
+
'review_base' => @review_base_url
|
174
|
+
}
|
175
|
+
end
|
176
|
+
|
127
177
|
end
|
178
|
+
|
128
179
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# @author Matthieu Ciappara <ciappa_m@modulotech>
|
2
2
|
# An error encountered during an operation with additional data.
|
3
3
|
class Modulorails::ErrorData
|
4
|
+
|
4
5
|
# @!attribute r errors
|
5
6
|
# An error message or an array of error messages (those will be joined by a coma and a space).
|
6
7
|
# @!attribute r exception
|
@@ -18,4 +19,5 @@ class Modulorails::ErrorData
|
|
18
19
|
def success?
|
19
20
|
false
|
20
21
|
end
|
22
|
+
|
21
23
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# @author Matthieu CIAPPARA <ciappa_m@modulotech.fr>
|
2
2
|
# An exception representing an invalid format for a given field.
|
3
3
|
class Modulorails::InvalidFormatError < Modulorails::BaseError
|
4
|
+
|
4
5
|
# @!attribute r field
|
5
6
|
# The name of the field that had a wrong format.
|
6
7
|
attr_reader :field
|
@@ -11,4 +12,5 @@ class Modulorails::InvalidFormatError < Modulorails::BaseError
|
|
11
12
|
|
12
13
|
@field = field
|
13
14
|
end
|
15
|
+
|
14
16
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# @author Matthieu CIAPPARA <ciappa_m@modulotech.fr>
|
2
2
|
# An exception representing an invalid value for a given field.
|
3
3
|
class Modulorails::InvalidValueError < Modulorails::BaseError
|
4
|
+
|
4
5
|
# @!attribute r field
|
5
6
|
# The name of the field that had a wrong value.
|
6
7
|
attr_reader :field
|
@@ -11,4 +12,5 @@ class Modulorails::InvalidValueError < Modulorails::BaseError
|
|
11
12
|
|
12
13
|
@field = field
|
13
14
|
end
|
15
|
+
|
14
16
|
end
|
data/lib/modulorails/railtie.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
require_relative '../../app/helpers/modulorails/application_helper'
|
2
2
|
|
3
3
|
module Modulorails
|
4
|
+
|
4
5
|
# Bind in the Rails lifecycle
|
5
6
|
class Railtie < ::Rails::Railtie
|
7
|
+
|
6
8
|
# Update and add gems before we load the configuration
|
7
9
|
config.before_configuration do
|
8
10
|
# Currently, we limit everything to the development environment
|
@@ -35,7 +37,7 @@ module Modulorails
|
|
35
37
|
# Currently, we limit everything to the development environment
|
36
38
|
if Rails.env.development?
|
37
39
|
# Load translations
|
38
|
-
I18n.load_path += [File.expand_path('
|
40
|
+
I18n.load_path += [File.expand_path('../../config/locales/en.yml', __dir__)]
|
39
41
|
|
40
42
|
# Effectively send the data to the intranet
|
41
43
|
Modulorails.send_data
|
@@ -53,5 +55,7 @@ module Modulorails
|
|
53
55
|
Modulorails.self_update
|
54
56
|
end
|
55
57
|
end
|
58
|
+
|
56
59
|
end
|
60
|
+
|
57
61
|
end
|
@@ -2,6 +2,7 @@
|
|
2
2
|
# The base class for services. Should be implemented by ApplicationService following the model of
|
3
3
|
# ActiveRecord::Base and ApplicationRecord.
|
4
4
|
class Modulorails::BaseService
|
5
|
+
|
5
6
|
# Allow to instantiate the service and call the service in one go.
|
6
7
|
if Modulorails::COMPARABLE_RUBY_VERSION < Gem::Version.new('3.0')
|
7
8
|
def self.call(*args, &block)
|
@@ -28,7 +29,7 @@ class Modulorails::BaseService
|
|
28
29
|
end
|
29
30
|
|
30
31
|
# Shamelessly copied from text_helper
|
31
|
-
def self.pluralize(count, singular, plural_arg
|
32
|
+
def self.pluralize(count, singular, plural_arg=nil, plural: plural_arg, locale: I18n.locale)
|
32
33
|
word = if count == 1 || count =~ /^1(\.0+)?$/
|
33
34
|
singular
|
34
35
|
else
|
@@ -58,25 +59,27 @@ class Modulorails::BaseService
|
|
58
59
|
data = yield
|
59
60
|
end
|
60
61
|
|
61
|
-
SuccessData.new(data)
|
62
|
+
::Modulorails::SuccessData.new(data)
|
62
63
|
rescue ActiveRecord::RecordInvalid => e
|
63
64
|
# Known error, no need for a log, it just needs to be returned
|
64
|
-
ErrorData.new(e.message, exception: e)
|
65
|
+
::Modulorails::ErrorData.new(e.message, exception: e)
|
65
66
|
rescue StandardError => e
|
66
67
|
# Unknown error, log the error
|
67
68
|
Rails.logger.error("#{self}: #{e.message}")
|
68
|
-
Rails.logger.error("Local variables: #{local_variables.map! { |v|
|
69
|
+
Rails.logger.error("Local variables: #{local_variables.map! { |v|
|
70
|
+
{ v => binding.local_variable_get(v) }
|
71
|
+
} }")
|
69
72
|
Rails.logger.error(e.backtrace&.join("\n"))
|
70
73
|
|
71
74
|
# Return the error
|
72
|
-
ErrorData.new(e.message, exception: e)
|
75
|
+
::Modulorails::ErrorData.new(e.message, exception: e)
|
73
76
|
end
|
74
77
|
|
75
78
|
# Cast the date/datetime parameters to time with zones.
|
76
79
|
# @param from [String,ActiveSupport::TimeWithZone] the minimum date
|
77
80
|
# @param to [String,ActiveSupport::TimeWithZone] the maximum date
|
78
81
|
# @return [[ActiveSupport::TimeWithZone, ActiveSupport::TimeWithZone]] The given dates casted.
|
79
|
-
def params_to_time(from, to
|
82
|
+
def params_to_time(from, to=nil)
|
80
83
|
from = from.is_a?(String) && from.present? ? from.to_time_with_zone : from
|
81
84
|
to = if to.is_a?(String) && to.present?
|
82
85
|
to = to.to_time_with_zone
|
@@ -92,7 +95,7 @@ class Modulorails::BaseService
|
|
92
95
|
end
|
93
96
|
|
94
97
|
# Shamelessly copied from text_helper
|
95
|
-
def pluralize(count, singular, plural_arg
|
98
|
+
def pluralize(count, singular, plural_arg=nil, plural: plural_arg, locale: I18n.locale)
|
96
99
|
self.class.pluralize(count, singular, plural_arg, plural: plural, locale: locale)
|
97
100
|
end
|
98
101
|
|
@@ -141,7 +144,9 @@ class Modulorails::BaseService
|
|
141
144
|
value = params.dig(*keys)
|
142
145
|
|
143
146
|
if value.respond_to?(:each)
|
144
|
-
raise InvalidValueError.new(keys.join('/')) unless value.all? { |v|
|
147
|
+
raise InvalidValueError.new(keys.join('/')) unless value.all? { |v|
|
148
|
+
allowed_values.include?(v)
|
149
|
+
}
|
145
150
|
else
|
146
151
|
return nil if !value && allow_nil
|
147
152
|
|
@@ -162,11 +167,9 @@ class Modulorails::BaseService
|
|
162
167
|
value = params.dig(*keys)
|
163
168
|
|
164
169
|
unless value
|
165
|
-
if allow_nil
|
166
|
-
|
167
|
-
|
168
|
-
raise InvalidValueError.new(keys.join('/'))
|
169
|
-
end
|
170
|
+
return nil if allow_nil
|
171
|
+
|
172
|
+
raise InvalidValueError.new(keys.join('/'))
|
170
173
|
end
|
171
174
|
|
172
175
|
result = model.find_by(field => value)
|
@@ -187,11 +190,9 @@ class Modulorails::BaseService
|
|
187
190
|
values = params.dig(*keys)
|
188
191
|
|
189
192
|
if values.blank?
|
190
|
-
if allow_nil
|
191
|
-
|
192
|
-
|
193
|
-
raise InvalidValueError.new(keys.join('/'))
|
194
|
-
end
|
193
|
+
return nil if allow_nil
|
194
|
+
|
195
|
+
raise InvalidValueError.new(keys.join('/'))
|
195
196
|
end
|
196
197
|
|
197
198
|
results = model.where(field => values)
|
@@ -200,4 +201,5 @@ class Modulorails::BaseService
|
|
200
201
|
|
201
202
|
results
|
202
203
|
end
|
204
|
+
|
203
205
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# @author Matthieu Ciappara <ciappa_m@modulotech>
|
2
2
|
# A success resulting from an operation with optional additional data.
|
3
3
|
class Modulorails::SuccessData
|
4
|
+
|
4
5
|
# @!attribute r data
|
5
6
|
# An object to transport some data (for instance the result of the operation). Defaults to nil.
|
6
7
|
attr_reader :data
|
@@ -14,4 +15,5 @@ class Modulorails::SuccessData
|
|
14
15
|
def success?
|
15
16
|
true
|
16
17
|
end
|
18
|
+
|
17
19
|
end
|
@@ -1,8 +1,11 @@
|
|
1
1
|
module Modulorails
|
2
|
+
|
2
3
|
module Validators
|
4
|
+
|
3
5
|
# Author: Matthieu 'ciappa_m' Ciappara
|
4
6
|
# This holds the rules to configure the database by respecting Modulotech's norms.
|
5
7
|
class DatabaseConfiguration
|
8
|
+
|
6
9
|
def initialize
|
7
10
|
# All rules are invalid by default
|
8
11
|
@rules = {
|
@@ -37,19 +40,23 @@ module Modulorails
|
|
37
40
|
check_rules_for_environment(database_configuration, :development)
|
38
41
|
check_rules_for_environment(database_configuration, :test)
|
39
42
|
|
40
|
-
|
43
|
+
fetch_invalid_rules
|
41
44
|
end
|
42
45
|
|
43
46
|
private
|
44
47
|
|
45
|
-
def
|
46
|
-
dev = @rules[:development].
|
47
|
-
test = @rules[:test].
|
48
|
-
general = @rules
|
48
|
+
def fetch_invalid_rules
|
49
|
+
dev = select_invalid_keys(@rules[:development]).map { |k| "development.#{k}" }
|
50
|
+
test = select_invalid_keys(@rules[:test]).map { |k| "test.#{k}" }
|
51
|
+
general = select_invalid_keys(@rules)
|
49
52
|
|
50
53
|
general + dev + test
|
51
54
|
end
|
52
55
|
|
56
|
+
def select_invalid_keys(hash)
|
57
|
+
hash.select { |_k, v| v == false }.keys
|
58
|
+
end
|
59
|
+
|
53
60
|
def check_standard_config_file_location
|
54
61
|
# Load the configuration
|
55
62
|
config = if Modulorails::COMPARABLE_RUBY_VERSION >= Gem::Version.new('3.1')
|
@@ -64,7 +71,7 @@ module Modulorails
|
|
64
71
|
@rules[:standard_config_file_location] = true
|
65
72
|
|
66
73
|
config
|
67
|
-
rescue StandardError
|
74
|
+
rescue StandardError
|
68
75
|
# An exception was raised, either the file is not a the standard location, either it just
|
69
76
|
# cannot be read. Either way, we consider the config as invalid
|
70
77
|
@rules[:standard_config_file_location] = false
|
@@ -74,13 +81,13 @@ module Modulorails
|
|
74
81
|
# The database for tests MUST NOT be the same as the development database since the test
|
75
82
|
# database is rewritten each time the tests are launched
|
76
83
|
def check_test_database_not_equals_dev_database(config)
|
77
|
-
|
78
|
-
|
84
|
+
@rules[:test_database_not_equals_dev_database] =
|
85
|
+
config['test']['database'] != config['development']['database']
|
79
86
|
end
|
80
87
|
|
81
88
|
# Check all rules for an environment
|
82
89
|
def check_rules_for_environment(config, env)
|
83
|
-
@rules[env].
|
90
|
+
@rules[env].each_key do |rule|
|
84
91
|
key = rule.to_s.gsub(/configurable_/, '')
|
85
92
|
check_configurable_key_for_environment(config, env, key)
|
86
93
|
end
|
@@ -94,6 +101,9 @@ module Modulorails
|
|
94
101
|
# Use of `!!` to convert `nil` to `false` and `0` to `true`
|
95
102
|
@rules[env][:"configurable_#{key}"] = !!valid_rule
|
96
103
|
end
|
104
|
+
|
97
105
|
end
|
106
|
+
|
98
107
|
end
|
108
|
+
|
99
109
|
end
|