rails_app_version 0.1.2 → 0.2.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: 381e86a1a9a44077393c49d8f813c3ddab906e0672021d5498fac963bf2640b7
4
- data.tar.gz: 5826b91f6d12cd73f08ac4a7a6f987021f0b82303f126e22d5cd608168318ec6
3
+ metadata.gz: f12fcf73c08d447843831ce2387b14fae8302f8d3ec2c08dd3548e471435c2a1
4
+ data.tar.gz: 88361140e3a6ac93c378aaf8e38f253864fb2bebc1920b81903fb305c4863631
5
5
  SHA512:
6
- metadata.gz: e522072844c9469560d3d199b2797cf0d9a494771e6df31fbba1349a4ba21d8b219c31443381080e803808c77df1a26b150886b744a053485131ddc7851d322f
7
- data.tar.gz: 5b1926f667890b37c4e58e52879623338bca9cf9b10c62ff25a2b730a0f0ddbd0cd9075dad7773457bca6d6675e0e9f3cbaf307e41b3788b297074e23f7ad94c
6
+ metadata.gz: ce3f381f908e7eb51dc36bf82cb0d1f32a521563f93d4c68642cba6f7a6e54a7a460f55333352b0aca4a1348e740f959a08c4333495e20e9e874843edbf2fde6
7
+ data.tar.gz: f7a240228914ad118252befd33fcaf60647194da681a72360265c7274715d388026e29815c2bdc025c8cc1014aa6c8a6daa9b6f62aaa70fca1cd65b2afb71071
data/Rakefile CHANGED
@@ -3,3 +3,8 @@ require "bundler/setup"
3
3
  load "rails/tasks/statistics.rake"
4
4
 
5
5
  require "bundler/gem_tasks"
6
+
7
+ # Load Rakefile of the dummy app
8
+ load "test/dummy/Rakefile"
9
+
10
+ task :default, %i[test]
@@ -2,3 +2,4 @@ shared:
2
2
  version: <%= Rails.root.join('VERSION').read.strip rescue '0.0.0' %>
3
3
  revision: <%= Rails.root.join('REVISION').read.strip rescue (`git rev-parse HEAD`.strip rescue '0') %>
4
4
  show_revision: <%= Rails.env.local? %>
5
+ environment: <%= ENV.fetch('RAILS_APP_ENV', Rails.env) %>
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsAppVersion
4
- VERSION = "0.1.2"
4
+ VERSION = "0.2.1"
5
5
  end
@@ -5,22 +5,48 @@ require "rails/application"
5
5
  require "rails_app_version/version"
6
6
 
7
7
  module RailsAppVersion
8
- class Engine < ::Rails::Engine
9
- attr_reader :app_config, :version, :environment
8
+ class Version < Gem::Version
9
+ # This method cache used by Rails.cache.fetch to generate a cache key
10
+ def to_cache_key
11
+ (to_s).parameterize
12
+ end
13
+ end
14
+ class Railtie < ::Rails::Railtie
15
+ attr_reader :app_config, :version, :env
16
+
17
+ def root
18
+ @root ||= Pathname.new(File.expand_path("..", __dir__))
19
+ end
20
+
21
+ rake_tasks do
22
+ namespace :app do
23
+ namespace :version do
24
+ desc "Copy config/app_version.yml to the main app config directory"
25
+ task :config do
26
+ source = RailsAppVersion::Railtie.root.join("config", "app_version.yml")
27
+ destination = Rails.root.join("config", "app_version.yml")
28
+
29
+ FileUtils.cp(source, destination)
30
+
31
+ puts "Installed app_version.yml to #{destination}"
32
+ end
33
+ end
34
+ end
35
+ end
10
36
 
11
37
  initializer "fetch_config" do |app|
12
38
  @app_config = begin
13
- app.config_for(:app_version)
39
+ app.config_for(:app_version, env: Rails.env)
14
40
  rescue RuntimeError
15
41
  # Load the default configuration from the gem, if the app does not have one
16
42
  require "erb"
17
- yaml = Engine.root.join("config", "app_version.yml")
43
+ yaml = Railtie.root.join("config", "app_version.yml")
18
44
  all_configs = ActiveSupport::ConfigurationFile.parse(yaml).deep_symbolize_keys
19
45
  all_configs[:shared]
20
46
  end
21
47
 
22
- @version = @app_config[:version]
23
- @environment = @app_config[:environment] || Rails.env
48
+ @version = Version.new(@app_config[:version])
49
+ @env = ActiveSupport::StringInquirer.new(@app_config[:environment] || Rails.env)
24
50
  end
25
51
  end
26
52
 
@@ -30,7 +56,7 @@ module RailsAppVersion
30
56
  included do
31
57
  def version
32
58
  @version ||= railties.find do |railtie|
33
- railtie.is_a?(RailsAppVersion::Engine)
59
+ railtie.is_a?(RailsAppVersion::Railtie)
34
60
  end.version
35
61
  end
36
62
  end
@@ -40,15 +66,14 @@ module RailsAppVersion
40
66
  extend ActiveSupport::Concern
41
67
 
42
68
  included do
43
- def environment
44
- @environment ||= railties.find do |railtie|
45
- railtie.is_a?(RailsAppVersion::Engine)
46
- end.environment
69
+ def env
70
+ @env ||= railties.find do |railtie|
71
+ railtie.is_a?(RailsAppVersion::Railtie)
72
+ end.env
47
73
  end
48
74
  end
49
75
  end
50
76
  end
51
77
 
52
-
53
78
  Rails::Application.include RailsAppVersion::AppVersion
54
79
  Rails::Application.include RailsAppVersion::AppEnvironment
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_app_version
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abdelkader Boudih
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-15 00:00:00.000000000 Z
11
+ date: 2024-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '7.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: dotenv-rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  description: Get the version of your Rails app
28
42
  email:
29
43
  - terminale@gmail.com