modulorails 1.7.0 → 1.7.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1be41ee3e5898a6e283359c6df4525cd77cec83e6a37d255996316a305511722
4
- data.tar.gz: dec467bed1e055a3c0d11c948563eaa6eead755be40e6b7185cbb2678f54e180
3
+ metadata.gz: 32e635cab679e5afa08f8ab3ef42f5370502098330178492b1bd067d6b842fc7
4
+ data.tar.gz: eec6c93a7a28f5b8552a8e94cba08a3ed826867ad3fb8eef63b9318c3eff68b7
5
5
  SHA512:
6
- metadata.gz: a69ef3ab27fd2e422e5bc7ce588bfa46ca273281ca2e43de7336048b038c1328b22a970066856bd7320df0b144e637348e7d1139cce614c2d068083247d3f666
7
- data.tar.gz: 7952e968f9bdf475bfe2806933e7e5e5114e8418891dc4dc09809438eb20c804e48a1d85bca8ed558636db64c1b0eca501ea57da5ae03b0eaf4b943a0c466478
6
+ metadata.gz: 3ccabc6e05b83b6980df9ef747a5961445e2cb6d882bbdde2114697364caad9496c2900d581db3e1b1729e3bf02ed069cb3b2266ee0f74be1ebdf9b2b6fde087
7
+ data.tar.gz: f9233dfdbb1c7512550036d27dcb7329fedd15b78e07e439bba42a54a6f333e46d4ecc48046bda8e9325e5723f91600bd4b19ed9733c09028fd8efe87bfc379c
data/CHANGELOG.md CHANGED
@@ -4,6 +4,16 @@ This file is used to list changes made in each version of the gem.
4
4
 
5
5
  # Unreleased
6
6
 
7
+ # 1.7.1
8
+
9
+ The boot-resilience release. Hardens the gem against several boot-time crash paths so that information gathering and configuration generation can never prevent the host application from starting.
10
+
11
+ ## Fixes
12
+
13
+ - Fix `initialize_from_database` when the database is unreachable on Rails 7.1+. Connections are now established lazily at query time, so errors surface from `select_value` as `ActiveRecord::StatementInvalid` or adapter-level errors (e.g. `PG::ConnectionBad`) that don't inherit from `ActiveRecordError`. The rescue is broadened to `StandardError` so that DB metadata collection never prevents the application from booting (e.g. running `bin/rails db:create` on a fresh checkout).
14
+ - Guard `Modulorails::Data#initialize_from_configuration` against a missing `config.name`: fall back to the Rails application class name and use safe navigation when deriving `@environment_name`, so a forgotten `config.name '...'` no longer crashes the boot with `NoMethodError: undefined method 'parameterize' for nil`.
15
+ - Move the body construction in `Modulorails.send_data` inside its `begin`/`rescue` block so that an unexpected failure in `Modulorails::Data.new` (e.g. a malformed configuration) is caught instead of bubbling out of `after_initialize` and breaking Rails boot.
16
+
7
17
  # 1.7.0
8
18
 
9
19
  ## Improvements
@@ -74,12 +74,16 @@ module Modulorails
74
74
  # Get the gem's configuration to get the application's usual name, main dev and PM
75
75
  configuration = Modulorails.configuration
76
76
 
77
- # The data written by the user in the configuration
78
- # The name is the usual name of the project, the one used in conversations at Modulotech
79
- @name = configuration.name
77
+ # The data written by the user in the configuration.
78
+ # The name is the usual name of the project, the one used in conversations at Modulotech.
79
+ # Fall back to the Rails application class name if the user forgot to call `config.name`,
80
+ # so the gem does not crash the host application's boot.
81
+ @name = configuration.name || @rails_name
80
82
 
81
- # A version of the name suitable to name environment variables
82
- @environment_name = @name.parameterize.gsub('-', '_').gsub(/\b(\d)/, 'MT_\1').upcase
83
+ # A version of the name suitable to name environment variables.
84
+ # Use safe navigation so a fully unnamed application (no configuration name *and* no
85
+ # detectable Rails class name) leaves @environment_name as nil rather than raising.
86
+ @environment_name = @name&.parameterize&.gsub('-', '_')&.gsub(/\b(\d)/, 'MT_\1')&.upcase
83
87
 
84
88
  # The main developer, the lead developer, in short the developer to call when something's
85
89
  # wrong with the application ;)
@@ -116,7 +120,11 @@ module Modulorails
116
120
  # The version of the database engine; this request works only on MySQL and PostgreSQL
117
121
  # It should not be a problem since those are the sole database engines used at Modulotech
118
122
  @db_version = db_connection.select_value('SELECT version()')
119
- rescue ActiveRecord::NoDatabaseError, ActiveRecord::ConnectionNotEstablished => e
123
+ # Rescue broadly: on Rails 7.1+ the connection is established lazily at query time, so the
124
+ # error class can be ActiveRecord::StatementInvalid or even an adapter-level error like
125
+ # PG::ConnectionBad that does not inherit from ActiveRecordError. Collecting DB metadata
126
+ # must never prevent the application from booting.
127
+ rescue StandardError => e
120
128
  warn("[Modulorails] Error: #{e.message}")
121
129
  end
122
130
 
@@ -1,6 +1,6 @@
1
1
  module Modulorails
2
2
 
3
- VERSION = '1.7.0'.freeze
3
+ VERSION = '1.7.1'.freeze
4
4
 
5
5
  # Useful to compare the current Ruby version
6
6
  COMPARABLE_RUBY_VERSION = Gem::Version.new(RUBY_VERSION)
data/lib/modulorails.rb CHANGED
@@ -86,11 +86,13 @@ module Modulorails
86
86
  'Content-Type' => 'application/json', 'X-MODULORAILS-TOKEN' => configuration.api_key
87
87
  }
88
88
 
89
- # Define the JSON body of the request
90
- body = data.to_params.to_json
91
-
92
- # Prevent HTTParty to raise error and crash the server in dev
89
+ # Prevent HTTParty *and* data collection failures from crashing the server in dev.
90
+ # `data` lazily instantiates `Modulorails::Data`, which gathers DB/git/gem metadata; any
91
+ # unexpected failure there must not propagate out of `send_data`.
93
92
  begin
93
+ # Build the JSON body of the request
94
+ body = data.to_params.to_json
95
+
94
96
  # Post to the configured endpoint on the Intranet
95
97
  response = HTTParty.post(configuration.endpoint, headers: headers, body: body)
96
98
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: modulorails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthieu Ciappara