rails-env 1.0.5 → 1.0.6

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
  SHA1:
3
- metadata.gz: 090040b7adbed72a4e3cf77672bc5ab2d35d8cfd
4
- data.tar.gz: 7791272c42622b829b5b5d7a409b96f2b16b75f2
3
+ metadata.gz: ce82d44b07a02c08c130d1017570eeca3b1aa96a
4
+ data.tar.gz: 59bd44ea9ae33fc99450521f257fc2c26cdbb4ae
5
5
  SHA512:
6
- metadata.gz: fe41ee71ac13c65069d27a107c868dae6e895f0adfdb5856cc6f244d82c70e8f6f89bd17a952736d26173adaf71f49fd0acffed5cb737a04ecc26d87f9dc9a6d
7
- data.tar.gz: 1ed4c557662ce1858fd7414b0ad66b8613bac26981b904f484d4c1cb7e2a6715b3eed21942c34f3e9d2557db173b9d81b30fdaf847a62aba98efe3669a42be8b
6
+ metadata.gz: c3a1fdd95cdb42bce025a436e5c4ce81a6f55d6912d9bc679cda58b9caca68ed6e014487e659ab96d045d6429194635c7c84a77c84d03853bee41240929377c3
7
+ data.tar.gz: e146a9f72d26c5bc3a79bb5b82d04a4729928ca262fc7b4869324ffeabf47628170ec3c7eee0f1ac8dfc85a5ad34a5fd298125c537095ee35955e86f93812fd6
data/.gitignore CHANGED
@@ -3,6 +3,7 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
+ gemfiles/*.lock
6
7
  Gemfile.lock
7
8
  InstalledFiles
8
9
  _yardoc
@@ -0,0 +1,9 @@
1
+ sudo: false
2
+ cache: bundler
3
+ rvm:
4
+ - "2.2.4"
5
+ - "2.3.0"
6
+ script: bundle exec rake
7
+ gemfile:
8
+ - gemfiles/rails_4_2.gemfile
9
+ - gemfiles/rails_5_0.gemfile
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # rails-env
2
2
 
3
+ [![Build Status](https://travis-ci.org/fnando/rails-env.svg)](https://travis-ci.org/fnando/rails-env)
4
+ [![Code Climate](https://codeclimate.com/github/fnando/rails-env.png)](https://codeclimate.com/github/fnando/rails-env)
5
+ [![Gem Version](https://badge.fury.io/rb/rails-env.svg)](http://badge.fury.io/rb/rails-env)
6
+
3
7
  Avoid environment detection on Rails.
4
8
 
5
9
  ## Installation
@@ -44,6 +48,23 @@ Rails.env.on(:any) do
44
48
  end
45
49
  ```
46
50
 
51
+ ## Gotcha
52
+
53
+ Not all options can be defined through `Rails.env`. Rails propagates options on its engine file, meaning that every option defined on `config` afterwards must be manually propagated.
54
+
55
+ It's hard to automatically propagate every existing option, so we have the most common options covered, as you can see the list below:
56
+
57
+ - action_controller
58
+ - action_mailer
59
+ - action_view
60
+ - active_job
61
+ - active_record
62
+ - time_zone
63
+ - auto/eager load paths
64
+ - i18n
65
+
66
+ If you need to set any option not covered by rails-env, [please open a ticket](https://github.com/fnando/rails-env/issues/new).
67
+
47
68
  ## Upgrading from previous versions
48
69
 
49
70
  Previous versions used to yield the configuration; this is no longer true on 1.0+.
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+ gemspec path: ".."
3
+
4
+ gem "rails", "~> 4.2.5"
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+ gemspec path: ".."
3
+
4
+ gem "rails", "~> 5.0.0.beta3"
@@ -29,6 +29,7 @@ module RailsEnv
29
29
  propagate(:active_job, "::ActiveJob::Base")
30
30
  propagate(:active_record, "::ActiveRecord::Base")
31
31
  propagate(:time_zone, "::Time", :zone)
32
+ propagate_autoload_paths
32
33
  propagate_i18n
33
34
  end
34
35
 
@@ -42,6 +43,17 @@ module RailsEnv
42
43
  I18n.load_path += config.i18n.load_path if config.i18n.load_path
43
44
  end
44
45
 
46
+ def self.propagate_autoload_paths
47
+ all_autoload_paths = (
48
+ config.autoload_paths +
49
+ config.eager_load_paths +
50
+ config.autoload_once_paths
51
+ ).uniq
52
+
53
+ ActiveSupport::Dependencies.autoload_paths.unshift(*all_autoload_paths)
54
+ ActiveSupport::Dependencies.autoload_once_paths.unshift(*config.autoload_once_paths)
55
+ end
56
+
45
57
  def self.propagate(options_name, target_name, target_property = nil)
46
58
  return unless Object.const_defined?(target_name)
47
59
  return unless config.respond_to?(options_name)
@@ -49,7 +61,7 @@ module RailsEnv
49
61
  target = Object.const_get(target_name)
50
62
  options = config.public_send(options_name)
51
63
 
52
- if options.is_a?(Enumerable)
64
+ if options.is_a?(Hash)
53
65
  options.each do |key, value|
54
66
  target.public_send("#{key}=", value) if target.respond_to?("#{key}=")
55
67
  end
@@ -1,3 +1,3 @@
1
1
  module RailsEnv
2
- VERSION = "1.0.5"
2
+ VERSION = "1.0.6"
3
3
  end
@@ -4,6 +4,7 @@ require "bundler/setup"
4
4
  require "rails"
5
5
  require "action_mailer/railtie"
6
6
  require "action_view/railtie"
7
+ require "action_controller/railtie"
7
8
  require "active_job/railtie"
8
9
  require "rails-env"
9
10
 
@@ -11,6 +11,10 @@ class ConfigPropagationTest < Minitest::Test
11
11
  config.i18n.default_locale = "pt-BR"
12
12
  config.action_view.raise_on_missing_translations = true
13
13
  config.active_job.queue_adapter = :test
14
+
15
+ config.autoload_paths += ["#{__dir__}/al"]
16
+ config.autoload_once_paths += ["#{__dir__}/alo"]
17
+ config.eager_load_paths += ["#{__dir__}/el"]
14
18
  end
15
19
  end
16
20
 
@@ -51,4 +55,14 @@ class ConfigPropagationTest < Minitest::Test
51
55
  test "sets queue adapter" do
52
56
  assert_kind_of ActiveJob::QueueAdapters::TestAdapter, ActiveJob::Base.queue_adapter
53
57
  end
58
+
59
+ test "sets autoload_paths" do
60
+ assert ActiveSupport::Dependencies.autoload_paths.include?("#{__dir__}/al")
61
+ assert ActiveSupport::Dependencies.autoload_paths.include?("#{__dir__}/el")
62
+ assert ActiveSupport::Dependencies.autoload_paths.include?("#{__dir__}/alo")
63
+ end
64
+
65
+ test "sets autoload_once_paths" do
66
+ assert ActiveSupport::Dependencies.autoload_once_paths.include?("#{__dir__}/alo")
67
+ end
54
68
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-env
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
@@ -89,10 +89,13 @@ extra_rdoc_files: []
89
89
  files:
90
90
  - ".gitignore"
91
91
  - ".rspec"
92
+ - ".travis.yml"
92
93
  - Gemfile
93
94
  - LICENSE.txt
94
95
  - README.md
95
96
  - Rakefile
97
+ - gemfiles/rails_4_2.gemfile
98
+ - gemfiles/rails_5_0.gemfile
96
99
  - lib/rails-env.rb
97
100
  - lib/rails-env/version.rb
98
101
  - rails-env.gemspec