rails_app_version 1.2.4 → 1.3.0

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: bb48e4aced45b5ef329637e79b28124a30738a27150af084d32d10f648f9afd5
4
- data.tar.gz: 004f482315db18e853c4f372bd480abf7b295c62fc6e49af1f970d046223ac2e
3
+ metadata.gz: c41e184fea20b627c872461c8fa973f24e1d7796ab17f285139254c5dea9347b
4
+ data.tar.gz: 37a270bd254b40ae1266f2ccf6ca3333e9eeea4e045487b5c6ba9c71a66f25da
5
5
  SHA512:
6
- metadata.gz: b3002877e2c16298b37022d68ef7a1205321e16734f77c154f489450b9b464836dd02993fb8cbff1b68d861e276fad04e94685dfe0cc55d2cbb9ecf834da74fb
7
- data.tar.gz: '09c8b2e6a8c7dbf311a3db7d0f47d3dd0fb6a2368dc34e6432bd1f612845118c0c8d235ab669a127988c8879eae0c01f674f5d8f83c1568d589bd774ca2c564c'
6
+ metadata.gz: 937af3be9c3f04a6fad951baba9534bd55f8c71ffe5b353c3ff57820987b60be5465b771acd4d5409f2501c9b9f36f4fc976d2d01cc2e9945aed274abb14b725
7
+ data.tar.gz: 6d8c60f28f77268385bb89eb1c4b791226359bf29b50af21be981e9dac9c69c036f238c31de69830d568b88df7df4eadf6332477de6a1f9295f2a5c0054815d3
data/Rakefile CHANGED
@@ -1,7 +1,5 @@
1
1
  require "bundler/setup"
2
2
 
3
- load "rails/tasks/statistics.rake"
4
-
5
3
  require "bundler/gem_tasks"
6
4
 
7
5
  # Load Rakefile of the dummy app
@@ -1,5 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RailsAppVersion
2
4
  class Railtie < ::Rails::Railtie
5
+ CONFIG_FILE = "app_version.yml".freeze
6
+
3
7
  class << self
4
8
  def root
5
9
  @root ||= Pathname.new(File.expand_path(File.expand_path("../../", __dir__)))
@@ -9,52 +13,62 @@ module RailsAppVersion
9
13
  attr_reader :app_config, :version, :env
10
14
 
11
15
  rake_tasks do
12
- namespace :app do
13
- namespace :version do
14
- desc "Copy config/app_version.yml to the main app config directory"
15
- task :config do
16
- source = Railtie.root.join("config", "app_version.yml")
17
- destination = Rails.root.join("config", "app_version.yml")
18
-
19
- FileUtils.cp(source, destination)
20
-
21
- puts "Installed app_version.yml to #{destination}"
22
- end
23
- end
24
- end
16
+ load File.expand_path("../../tasks/app_version_tasks.rake", __FILE__)
25
17
  end
26
18
 
27
- # Console
28
19
  console do
29
- # rubocop:disable Rails/Output
30
- puts "Welcome to the Rails console!"
31
- puts "Ruby version: #{RUBY_VERSION}"
32
- puts "Application environment: #{Rails.application.env}"
33
- puts "Application version: #{Rails.application.version}"
34
- puts "To exit, press `Ctrl + D`."
35
- # rubocop:enable Rails/Output
20
+ print_console_banner
36
21
  end
37
22
 
38
- initializer "fetch_config" do |app|
39
- @app_config = begin
40
- app.config_for(:app_version, env: Rails.env)
41
- rescue RuntimeError => e # file is not found
42
- # Load the default configuration from the gem
43
- require "erb"
44
- yaml = Railtie.root.join("config", "app_version.yml")
45
- all_configs = ActiveSupport::ConfigurationFile.parse(yaml).deep_symbolize_keys
46
- all_configs[:shared]
47
- end
48
- @version = RailsAppVersion::Version.create(@app_config[:version], @app_config[:revision])
23
+ initializer "rails_app_version.fetch_config" do |app|
24
+ @app_config = load_config(app)
25
+ @version = Version.create(@app_config[:version], @app_config[:revision])
49
26
  @env = ActiveSupport::StringInquirer.new(@app_config.fetch(:environment, Rails.env))
50
27
  end
51
28
 
52
- initializer "middleware" do |app|
29
+ initializer "rails_app_version.middleware" do |app|
53
30
  # Add the middleware to the stack if enabled
54
31
  if @app_config.dig(:middleware, :enabled)
55
32
  options = @app_config.dig(:middleware, :options) || {}
56
- app.middleware.insert_before Rails::Rack::Logger, RailsAppVersion::AppInfoMiddleware, **options
33
+ app.middleware.insert_before Rails::Rack::Logger, AppInfoMiddleware, options
57
34
  end
58
35
  end
36
+
37
+ initializer "rails_app_version.extend_application" do |app|
38
+ Rails::Application.include AppEnvironment
39
+ Rails::Application.include AppVersion
40
+ end
41
+
42
+ private
43
+
44
+ def load_config(app)
45
+ app.config_for(:app_version, env: Rails.env)
46
+ rescue StandardError => e
47
+ Rails.logger.warn("Could not load app_version.yml: #{e.message}. Using default configuration.")
48
+ load_default_config
49
+ end
50
+
51
+ def load_default_config
52
+ yaml_path = Railtie.root.join("config", CONFIG_FILE)
53
+ all_configs = parse_yaml_config(yaml_path)
54
+ all_configs[:shared] || {}
55
+ end
56
+
57
+ def parse_yaml_config(path)
58
+ return {} unless File.exist?(path)
59
+
60
+ require "erb"
61
+ ActiveSupport::ConfigurationFile.parse(path).deep_symbolize_keys
62
+ end
63
+
64
+ def self.print_console_banner
65
+ # rubocop:disable Rails/Output
66
+ puts "Welcome to the Rails console!"
67
+ puts "Ruby version: #{RUBY_VERSION}"
68
+ puts "Application environment: #{Rails.application.env}"
69
+ puts "Application version: #{Rails.application.version&.full}"
70
+ puts "To exit, press `Ctrl + D`."
71
+ # rubocop:enable Rails/Output
72
+ end
59
73
  end
60
74
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsAppVersion
4
- VERSION = "1.2.4"
4
+ VERSION = "1.3.0"
5
5
 
6
6
  class Version < Gem::Version
7
7
  attr_reader :major, :minor, :patch, :pre, :revision
@@ -3,17 +3,13 @@
3
3
  require "rails"
4
4
  require "rails/application"
5
5
  require "rails_app_version/version"
6
- require "rails_app_version/railtie"
7
6
  require "rails_app_version/app_version"
8
7
  require "rails_app_version/app_environment"
9
- require "rails_app_version/version"
10
8
  require "action_controller/railtie"
9
+ require "rails_app_version/railtie"
11
10
 
12
11
  module RailsAppVersion
13
12
  extend ActiveSupport::Autoload
14
13
 
15
14
  autoload :AppInfoMiddleware
16
15
  end
17
-
18
- Rails::Application.include RailsAppVersion::AppVersion
19
- Rails::Application.include RailsAppVersion::AppEnvironment
@@ -0,0 +1,26 @@
1
+ # lib/tasks/app_version_tasks.rake
2
+ namespace :app do
3
+ namespace :version do
4
+ desc "Copy config/app_version.yml to the main app config directory"
5
+ task :config do
6
+ source = RailsAppVersion::Railtie.root.join("config", RailsAppVersion::Railtie::CONFIG_FILE)
7
+ destination = Rails.root.join("config", RailsAppVersion::Railtie::CONFIG_FILE)
8
+
9
+ if File.exist?(destination)
10
+ puts "Config file already exists at #{destination}"
11
+ print "Overwrite? (y/n): "
12
+ next unless $stdin.gets.strip.downcase == "y"
13
+ end
14
+
15
+ FileUtils.cp(source, destination)
16
+ puts "Installed #{RailsAppVersion::Railtie::CONFIG_FILE} to #{destination}"
17
+ end
18
+
19
+ desc "Display current application version information"
20
+ task info: :environment do
21
+ puts "Application version: #{Rails.application.version}"
22
+ puts "Environment: #{Rails.application.env}"
23
+ puts "Config: #{Rails.application.app_config.inspect}"
24
+ end
25
+ end
26
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_app_version
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.4
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abdelkader Boudih
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-01-01 00:00:00.000000000 Z
10
+ date: 2025-03-14 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: railties
@@ -73,6 +73,7 @@ files:
73
73
  - lib/rails_app_version/app_version.rb
74
74
  - lib/rails_app_version/railtie.rb
75
75
  - lib/rails_app_version/version.rb
76
+ - lib/tasks/app_version_tasks.rake
76
77
  homepage: https://github.com/seuros/rails_app_version
77
78
  licenses: []
78
79
  metadata:
@@ -94,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
95
  - !ruby/object:Gem::Version
95
96
  version: '0'
96
97
  requirements: []
97
- rubygems_version: 3.6.2
98
+ rubygems_version: 3.6.5
98
99
  specification_version: 4
99
100
  summary: Get the version of your Rails app
100
101
  test_files: []