rails_app_version 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c349aa9229b34d82b9649759bc0bf6874ac3ec0f395f1a4d7bdd82a0ecfcbcc4
4
- data.tar.gz: fa57ffd7636b51b2dfcabda06d3d387a6e5c1d2145a024d99ba6026f36258b7c
3
+ metadata.gz: ec8b9fb82abafba7d8a6cc3e95b908be05ff5ed00b1150cdc8002bfa65bd1a23
4
+ data.tar.gz: 16aa8846723ac2fe2321139bd125084357fb739cdd23fd86a0955a4ade4eb1ec
5
5
  SHA512:
6
- metadata.gz: 20034d4a7cd45ccf939ee1501ff6b5313e066e852565d635d2e711a22ce12ab102c3e1a538580476cb188882a916df7a014c9c329f42b94eef39bcf8a84b44cb
7
- data.tar.gz: 5b6b218c9ddf5bf17c6a40cdf8c37eb78c84489e9ede694765083122fbe5d874b8c8d3c7e6c29a154ebb2d7df8f0b4707288b1640aecd9a3a0c79289e4772fc9
6
+ metadata.gz: a0057f8dbd4ee9e2ab10ff7d0b8f795ede4c4a3b8644cff9a31d4b7683cd6d7451ed01ac22b5aa51f4fd2d80b50545205bd27365059fc428c6c903f77cb5d290
7
+ data.tar.gz: 181f9d0d1def9eeca5c46034ad0848cd1094d0fd4ba9ecd080c2772b331d62e634bd7c2e60b5d01f9bf5696705f58142953bf0110085b42a73bbf85bb1a5734f
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.1"
4
+ VERSION = "0.2.0"
5
5
  end
@@ -1,14 +1,38 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "rails"
4
+ require "rails/application"
3
5
  require "rails_app_version/version"
4
6
 
5
7
  module RailsAppVersion
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
6
14
  class Engine < ::Rails::Engine
7
- attr_reader :app_config, :version, :environment
15
+ attr_reader :app_config, :version, :env
16
+
17
+ rake_tasks do
18
+ namespace :app do
19
+ namespace :version do
20
+ desc "Copy config/app_version.yml to the main app config directory"
21
+ task :config do
22
+ source = RailsAppVersion::Engine.root.join("config", "app_version.yml")
23
+ destination = Rails.root.join("config", "app_version.yml")
24
+
25
+ FileUtils.cp(source, destination)
26
+
27
+ puts "Installed app_version.yml to #{destination}"
28
+ end
29
+ end
30
+ end
31
+ end
8
32
 
9
33
  initializer "fetch_config" do |app|
10
34
  @app_config = begin
11
- app.config_for(:app_version)
35
+ app.config_for(:app_version, env: Rails.env)
12
36
  rescue RuntimeError
13
37
  # Load the default configuration from the gem, if the app does not have one
14
38
  require "erb"
@@ -17,13 +41,8 @@ module RailsAppVersion
17
41
  all_configs[:shared]
18
42
  end
19
43
 
20
- @version = @app_config[:version]
21
- @environment = @app_config[:environment] || Rails.env
22
- end
23
- initializer "patch_application" do |app|
24
- # Inject the module into the application
25
- app.class.send(:include, RailsAppVersion::AppVersion)
26
- app.class.send(:include, RailsAppVersion::AppEnvironment)
44
+ @version = Version.new(@app_config[:version])
45
+ @env = ActiveSupport::StringInquirer.new(@app_config[:environment] || Rails.env)
27
46
  end
28
47
  end
29
48
 
@@ -43,11 +62,14 @@ module RailsAppVersion
43
62
  extend ActiveSupport::Concern
44
63
 
45
64
  included do
46
- def environment
47
- @environment ||= railties.find do |railtie|
65
+ def env
66
+ @env ||= railties.find do |railtie|
48
67
  railtie.is_a?(RailsAppVersion::Engine)
49
- end.environment
68
+ end.env
50
69
  end
51
70
  end
52
71
  end
53
72
  end
73
+
74
+ Rails::Application.include RailsAppVersion::AppVersion
75
+ 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.1
4
+ version: 0.2.0
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-14 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