modulorails 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -0
- data/Gemfile.lock +2 -1
- data/config/locales/en.yml +16 -0
- data/lib/generators/gitlabci_generator.rb +1 -1
- data/lib/generators/templates/.modulorails-gitlab-ci +3 -0
- data/lib/modulorails.rb +14 -2
- data/lib/modulorails/configuration.rb +3 -2
- data/lib/modulorails/data.rb +7 -2
- data/lib/modulorails/railtie.rb +6 -0
- data/lib/modulorails/updater.rb +42 -0
- data/lib/modulorails/version.rb +1 -1
- data/modulorails.gemspec +1 -0
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 92b2390033b3083f0829661ac44665f58f8eb438fb095d32c803ae5cea51c488
|
4
|
+
data.tar.gz: 5e13ccdb0a64f7b32ac594601f4f2415f081a16284e9c73cb1953c3e5cc47497
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e9e8885a9c648e7de6af49c3fa66ab59243714eda2449cd8398f4c09efa2fa5f744d71db7aa68f91a8f9912282c416e6e91f8c665b1035ea376974702251924
|
7
|
+
data.tar.gz: c15837070582d0a901fdfeee1c1d0be86a67f5fe69efbcca39fb14921e2ee1c527dadca48ab0c89691679d8bcc9144586a2ab4309773b4a8e8771369cb8ef5c7
|
data/CHANGELOG.md
CHANGED
@@ -1 +1,17 @@
|
|
1
1
|
# CHANGELOG
|
2
|
+
|
3
|
+
This file is used to list changes made in each version of the gem.
|
4
|
+
|
5
|
+
# 0.2.0
|
6
|
+
|
7
|
+
Auto-update release.
|
8
|
+
|
9
|
+
- Add auto-update feature.
|
10
|
+
|
11
|
+
# 0.1.0
|
12
|
+
|
13
|
+
Initial release.
|
14
|
+
|
15
|
+
- Send configuration to intranet.
|
16
|
+
- Write CI/CD templates.
|
17
|
+
- Check database configuration.
|
data/Gemfile.lock
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
en:
|
2
|
+
modulorails:
|
3
|
+
standard_config_file_location: The database configuration file can not be found at config/database.yml
|
4
|
+
test_database_not_equals_dev_database: The test database is equal to the development database
|
5
|
+
development:
|
6
|
+
configurable_host: Host is not configurable for development environment
|
7
|
+
configurable_username: Username is not configurable for development environment
|
8
|
+
configurable_password: Password is not configurable for development environment
|
9
|
+
configurable_database: Database name is not configurable for development environment
|
10
|
+
configurable_port: Port is not configurable for development environment
|
11
|
+
test:
|
12
|
+
configurable_host: Host is not configurable for test environment
|
13
|
+
configurable_username: Username is not configurable for test environment
|
14
|
+
configurable_password: Password is not configurable for test environment
|
15
|
+
configurable_database: Database name is not configurable for test environment
|
16
|
+
configurable_port: Port is not configurable for test environment
|
@@ -124,7 +124,7 @@ class GitlabciGenerator < Rails::Generators::Base
|
|
124
124
|
file = '.modulorails-gitlab-ci'
|
125
125
|
|
126
126
|
# Create file to avoid this generator on next modulorails launch
|
127
|
-
|
127
|
+
copy_file(file, file)
|
128
128
|
|
129
129
|
say "Add #{file} to git"
|
130
130
|
%x(git add #{file})
|
data/lib/modulorails.rb
CHANGED
@@ -2,6 +2,7 @@ require 'modulorails/version'
|
|
2
2
|
require 'modulorails/configuration'
|
3
3
|
require 'modulorails/data'
|
4
4
|
require 'modulorails/validators/database_configuration'
|
5
|
+
require 'modulorails/updater'
|
5
6
|
require 'modulorails/railtie' if defined?(Rails::Railtie)
|
6
7
|
require 'generators/gitlabci_generator'
|
7
8
|
require 'httparty'
|
@@ -115,12 +116,23 @@ module Modulorails
|
|
115
116
|
invalid_rules = Modulorails::Validators::DatabaseConfiguration.call
|
116
117
|
return true if invalid_rules.empty?
|
117
118
|
|
118
|
-
puts('[Modulorails] The database configuration (config/database.yml) has
|
119
|
+
puts('[Modulorails] The database configuration (config/database.yml) has warnings:')
|
119
120
|
invalid_rules.each do |rule|
|
120
|
-
|
121
|
+
t_rule = I18n.t(rule, scope: :modulorails, locale: :en)
|
122
|
+
puts("[Modulorails] Invalid database configuration: #{t_rule}")
|
121
123
|
end
|
122
124
|
|
123
125
|
false
|
124
126
|
end
|
127
|
+
|
128
|
+
# @author Matthieu 'ciappa_m' Ciappara
|
129
|
+
#
|
130
|
+
# Check the last version of Modulorails available on rubygems and update if there was a
|
131
|
+
# publication
|
132
|
+
def self_update
|
133
|
+
Modulorails::Updater.call unless configuration.no_auto_update
|
134
|
+
rescue StandardError => e
|
135
|
+
puts("[Modulorails] An error occured: #{e.class} - #{e.message}")
|
136
|
+
end
|
125
137
|
end
|
126
138
|
end
|
@@ -3,7 +3,8 @@ module Modulorails
|
|
3
3
|
# The configuration of the gem
|
4
4
|
class Configuration
|
5
5
|
# All the keys to configure the gem
|
6
|
-
attr_accessor :_name, :_main_developer, :_project_manager, :_endpoint, :_api_key
|
6
|
+
attr_accessor :_name, :_main_developer, :_project_manager, :_endpoint, :_api_key,
|
7
|
+
:_no_auto_update
|
7
8
|
|
8
9
|
# This allows to define a DSL to configure the gem
|
9
10
|
# Example:
|
@@ -14,7 +15,7 @@ module Modulorails
|
|
14
15
|
# config.endpoint "intranet's endpoint"
|
15
16
|
# config.api_key "intranet's api key"
|
16
17
|
# end
|
17
|
-
%i[name main_developer project_manager endpoint api_key].each do |field|
|
18
|
+
%i[name main_developer project_manager endpoint api_key no_auto_update].each do |field|
|
18
19
|
define_method(field) do |value=nil|
|
19
20
|
# No value means we want to get the field
|
20
21
|
return send("_#{field}") unless value
|
data/lib/modulorails/data.rb
CHANGED
@@ -20,7 +20,12 @@ module Modulorails
|
|
20
20
|
# Get the gem's configuration to get the application's usual name, main dev and PM
|
21
21
|
configuration = Modulorails.configuration
|
22
22
|
# Get the database connection to identify the database used by the application
|
23
|
-
|
23
|
+
# or return nil if the database does not exist
|
24
|
+
db_connection = begin
|
25
|
+
ActiveRecord::Base.connection
|
26
|
+
rescue ActiveRecord::NoDatabaseError
|
27
|
+
nil
|
28
|
+
end
|
24
29
|
# Get the gem's specifications to fetch the versions of critical gems
|
25
30
|
loaded_specs = Gem.loaded_specs
|
26
31
|
|
@@ -64,7 +69,7 @@ module Modulorails
|
|
64
69
|
|
65
70
|
# The version of the database engine; this request works only on MySQL and PostgreSQL
|
66
71
|
# It should not be a problem since those are the sole database engines used at Modulotech
|
67
|
-
@db_version
|
72
|
+
@db_version = db_connection&.select_value('SELECT version()')
|
68
73
|
|
69
74
|
# The version of the ActiveRecord adapter
|
70
75
|
@adapter_version = loaded_specs[@adapter]&.version&.version
|
data/lib/modulorails/railtie.rb
CHANGED
@@ -5,6 +5,9 @@ module Modulorails
|
|
5
5
|
config.after_initialize do
|
6
6
|
# For now, we limit everything to the development environment
|
7
7
|
if Rails.env.development?
|
8
|
+
# Load translations
|
9
|
+
I18n.load_path += [File.expand_path('../../../config/locales/en.yml', __FILE__)]
|
10
|
+
|
8
11
|
# Effectively send the data to the intranet
|
9
12
|
Modulorails.send_data
|
10
13
|
|
@@ -13,6 +16,9 @@ module Modulorails
|
|
13
16
|
|
14
17
|
# Check database configuration
|
15
18
|
Modulorails.check_database_config
|
19
|
+
|
20
|
+
# Gem's self-update if a new version was released
|
21
|
+
Modulorails.self_update
|
16
22
|
end
|
17
23
|
end
|
18
24
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Modulorails
|
2
|
+
# Author: Matthieu 'ciappa_m' Ciappara
|
3
|
+
# This updates modulorails by editing the gemfile and running a bundle update
|
4
|
+
class Updater
|
5
|
+
LATEST_VERSION_URL = 'https://rubygems.org/api/v1/versions/modulorails/latest.json'.freeze
|
6
|
+
|
7
|
+
def self.call(*args)
|
8
|
+
new(*args).call
|
9
|
+
end
|
10
|
+
|
11
|
+
def call
|
12
|
+
# Get the last published version
|
13
|
+
@last_published_version = HTTParty.get(LATEST_VERSION_URL).parsed_response['version']
|
14
|
+
|
15
|
+
# Do nothing if we could not fetch the last published version (whatever the reason)
|
16
|
+
# Or if the current version is the same as the last published version
|
17
|
+
return if @last_published_version.nil? || @last_published_version == Modulorails::VERSION
|
18
|
+
|
19
|
+
# If the last published version is different from the current version, we update the gem
|
20
|
+
edit_gemfile
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def edit_gemfile
|
26
|
+
# Read the lines of the Gemfile
|
27
|
+
gemfile_location = Rails.root.join('Gemfile')
|
28
|
+
lines = File.readlines gemfile_location
|
29
|
+
|
30
|
+
# Search and replace the modulorails line
|
31
|
+
index = lines.index { |l| l =~ /gem\s['"]modulorails['"]/ }
|
32
|
+
lines[index].gsub!(/(\s*)gem\s['"]modulorails['"].*/,
|
33
|
+
"#{$1}gem 'modulorails', '= #{@last_published_version}'")
|
34
|
+
|
35
|
+
# Update the Gemfile
|
36
|
+
File.open(gemfile_location, 'w') { |f| f.puts(lines) }
|
37
|
+
|
38
|
+
# Update the gem
|
39
|
+
`bundle install || bundle update modulorails`
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/modulorails/version.rb
CHANGED
data/modulorails.gemspec
CHANGED
@@ -32,6 +32,7 @@ Gem::Specification.new do |spec|
|
|
32
32
|
spec.add_runtime_dependency 'railties', '>= 4.2.0'
|
33
33
|
spec.add_runtime_dependency 'git', '~> 1.7', '>= 1.7.0'
|
34
34
|
spec.add_runtime_dependency 'httparty'
|
35
|
+
spec.add_runtime_dependency 'i18n'
|
35
36
|
|
36
37
|
spec.add_development_dependency 'activerecord', '>= 4.2.0'
|
37
38
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: modulorails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.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: 2020-
|
11
|
+
date: 2020-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -58,6 +58,20 @@ dependencies:
|
|
58
58
|
- - ">="
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: i18n
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :runtime
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
61
75
|
- !ruby/object:Gem::Dependency
|
62
76
|
name: activerecord
|
63
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -96,13 +110,16 @@ files:
|
|
96
110
|
- Rakefile
|
97
111
|
- bin/console
|
98
112
|
- bin/setup
|
113
|
+
- config/locales/en.yml
|
99
114
|
- lib/generators/gitlabci_generator.rb
|
100
115
|
- lib/generators/templates/.gitlab-ci.yml
|
116
|
+
- lib/generators/templates/.modulorails-gitlab-ci
|
101
117
|
- lib/generators/templates/config/database-ci.yml
|
102
118
|
- lib/modulorails.rb
|
103
119
|
- lib/modulorails/configuration.rb
|
104
120
|
- lib/modulorails/data.rb
|
105
121
|
- lib/modulorails/railtie.rb
|
122
|
+
- lib/modulorails/updater.rb
|
106
123
|
- lib/modulorails/validators/database_configuration.rb
|
107
124
|
- lib/modulorails/version.rb
|
108
125
|
- modulorails.gemspec
|