envyable 1.1.1 → 1.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
  SHA1:
3
- metadata.gz: 3d4af1ced0824764bbac3e7f28bda8982ddc9d85
4
- data.tar.gz: f70751518161fba856b02d3cfe3a0d4039ca4552
3
+ metadata.gz: 2fbd50432fb934f5ea104f0d132571f52faae369
4
+ data.tar.gz: 3a9c3525fc21bed5cca528df0f940c3c082471e5
5
5
  SHA512:
6
- metadata.gz: e7866d20605d48c64e15f8f5b8a4d58ad6b41708c6e2468b00f77d7757d5db49dc37a94a8aaf2039732fd0b11c2786ec989c46e4e6693cfb6d3b4bbda369929f
7
- data.tar.gz: 9f514156650430d6ea34ef5d764e1c4eb7fe1f47b13377a47a33466c639bc11537e329c0af19a60b5e15518faa7d2577fd41aec2ad500e6281203db2a3accb31
6
+ metadata.gz: 3fa0fc79aa27d5f66cc7245cf9e93fb31f92624776f75bc99dd218100494937afdb3ce2191f564c7aff4b63f342c6d83c160f0e5d18abfb3732ade2bbc112588
7
+ data.tar.gz: fa43e0f9fe688c5ca72207718fbad81c04446815e542e15db7642314dcbf9b9207a7ac701bbf72af7367c7791161f6c6ba16e4b0530d479dfb00418bdcf45576
data/.gitignore CHANGED
@@ -17,3 +17,4 @@ test/tmp
17
17
  test/version_tmp
18
18
  tmp
19
19
  spec/sandbox
20
+ log/
data/README.md CHANGED
@@ -23,13 +23,11 @@ Or install it yourself as:
23
23
  Once the gem is included in your project, you can then use it to generate the
24
24
  default required files. Just run:
25
25
 
26
- ```
27
- $ envyable install
28
- ```
26
+ $ envyable install
29
27
 
30
28
  and you will get a `config` directory containing an `env.yml` and a
31
29
  `env.yml.example` file. If you have a `.gitignore` file this will also append
32
- the line
30
+ the line:
33
31
 
34
32
  ```yaml
35
33
  /config/env.yml
@@ -37,6 +35,15 @@ the line
37
35
 
38
36
  to your config so that you do not check in `/config/env.yml`.
39
37
 
38
+ If you have [Spring](https://github.com/rails/spring) bundled with your
39
+ application this will append the following line to `/config/spring.rb`:
40
+
41
+ ```ruby
42
+ Spring.watch 'config/env.yml'
43
+ ```
44
+
45
+ If the file `/config/spring.rb` does not exist, it will be created.
46
+
40
47
  ## Usage
41
48
 
42
49
  ### YAML file
@@ -51,11 +58,11 @@ test:
51
58
 
52
59
  ### Rails
53
60
 
54
- Once installed in a Rails app, add your yaml file at `config/env.yml`. The gem will load the correct environment on initialization of the application.
61
+ Once installed in a Rails app, add your yaml file at `config/env.yml`. The gem will load the correct environment on initialization of the application. If you are using Spring to load your Rails application, [add `config/env.yml` to Spring's watch list](https://github.com/rails/spring#watching-files-and-directories).
55
62
 
56
63
  ### Load Immediately
57
64
 
58
- If you have gems that require variables to be set earlier, then place `envyable` in the `Gemfile` before those gems and require `envyable/rails-now`:
65
+ If you have gems that require variables to be set earlier then place `envyable` in the `Gemfile` before those gems and require `envyable/rails-now`:
59
66
  ```
60
67
  gem 'envyable', require: 'envyable/rails-now'
61
68
  gem 'other-gem-that-requires-env-variables'
@@ -76,7 +83,11 @@ Envyable.load('config/env.yml')
76
83
 
77
84
  ### Version control
78
85
 
79
- It is not recommended that you check the yaml file in to version control. Personally, I like to check in a `env.yml.example` file that shows the required keys, but does not include any credentials.
86
+ It is not recommended that you check the yaml file in to version control. Personally, I like to check in a `env.yml.example` file that shows the required keys, but does not include any credentials. If you generate your Envyable files using the installer, `config/env.yml` will be added to your `.gitignore` file.
87
+
88
+ ## Troubleshooting
89
+
90
+ If your ENV values don't update when you modify `config/env.yml`, verify whether you have Spring (or another application preloader) that isn't configured to watch and reload when you update values. You should try configuring the preloader or just restarting it.
80
91
 
81
92
  ## Contributing
82
93
 
@@ -20,7 +20,7 @@ module Envyable
20
20
  # Envyable.load('config/application.yml', 'production')
21
21
  #
22
22
  # Returns nothing.
23
- def self.load(path, environment='development')
23
+ def self.load(path, environment = 'development')
24
24
  Loader.new(path).load(environment)
25
25
  end
26
26
  end
@@ -15,6 +15,12 @@ module Envyable
15
15
  "\n# Don't check in credentials \nconfig/env.yml"
16
16
  end
17
17
  end
18
+ if File.exist?("#{destination_root}/bin/spring")
19
+ create_file("config/spring.rb") unless File.exist?("#{destination_root}/config/spring.rb")
20
+ append_to_file("config/spring.rb") do
21
+ "\nSpring.watch 'config/env.yml'"
22
+ end
23
+ end
18
24
  end
19
25
  end
20
26
  end
@@ -13,7 +13,7 @@ module Envyable
13
13
  # resides.
14
14
  # loadable - a Hash or hashlike structure that the yaml file variables
15
15
  # should be loaded into (default: ENV).
16
- def initialize(path, loadable=ENV)
16
+ def initialize(path, loadable = ENV)
17
17
  @path = path
18
18
  @loadable = loadable
19
19
  end
@@ -28,7 +28,7 @@ module Envyable
28
28
  # load('production')
29
29
  #
30
30
  # Returns nothing.
31
- def load(environment='development')
31
+ def load(environment = 'development')
32
32
  if @yml ||= load_yml
33
33
  @yml.each { |key, value| set_value(key, value) }
34
34
  if @yml[environment]
@@ -1,3 +1,3 @@
1
1
  module Envyable
2
- VERSION = "1.1.1"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -38,5 +38,28 @@ describe Envyable::CLI do
38
38
  capture_io { cli.install }
39
39
  File.readlines(gitignore).any? { |line| line == "config/env.yml" }.must_equal true
40
40
  end
41
+
42
+ it "should create a file in config/spring.rb if it doesn't exist already" do
43
+ spring_rb = "#{cli.destination_root}/config/spring.rb"
44
+ cli = Envyable::CLI.new([], {}, :destination_root => destination_root(:with_spring_bin => true))
45
+ File.exist?(spring_rb).must_equal false
46
+ capture_io { cli.install }
47
+ File.exist?(spring_rb).must_equal true
48
+ end
49
+
50
+ it "should add config/env.yml to Spring's watch list" do
51
+ spring_rb = "#{cli.destination_root}/config/spring.rb"
52
+ cli = Envyable::CLI.new([], {}, :destination_root => destination_root(:with_spring_bin => true))
53
+ capture_io { cli.install }
54
+ File.readlines(spring_rb).any? { |line| line == "Spring.watch 'config/env.yml'" }.must_equal true
55
+ end
56
+
57
+ it "should add config/env.yml to Spring's watch list when spring.rb exists" do
58
+ spring_rb = "#{cli.destination_root}/config/spring.rb"
59
+ cli = Envyable::CLI.new([], {}, :destination_root => destination_root(:with_spring_bin => true, :with_spring_rb => true))
60
+ File.readlines(spring_rb).none? { |line| line == "Spring.watch 'config/env.yml'" }.must_equal true
61
+ capture_io { cli.install }
62
+ File.readlines(spring_rb).any? { |line| line == "Spring.watch 'config/env.yml'" }.must_equal true
63
+ end
41
64
  end
42
65
  end
@@ -1,16 +1,20 @@
1
1
  require 'fileutils'
2
2
  require 'rubygems'
3
3
  begin
4
- require "simplecov"
5
- require "codeclimate-test-reporter"
4
+ require 'simplecov'
5
+ require 'codeclimate-test-reporter'
6
6
  SimpleCov.start do
7
7
  formatter SimpleCov::Formatter::MultiFormatter.new([
8
8
  SimpleCov::Formatter::HTMLFormatter,
9
9
  CodeClimate::TestReporter::Formatter
10
10
  ])
11
- add_filter "/spec/"
11
+ add_filter '/spec/'
12
12
  end
13
13
  rescue LoadError
14
+ require 'logger'
15
+ logger = Logger.new('./log/test.log')
16
+ logger.info 'Couldn\'t load simplecov or codeclimate-test-reporter. Check ' \
17
+ 'your dependencies.'
14
18
  end
15
19
 
16
20
  gem 'minitest'
@@ -19,8 +23,16 @@ require 'minitest/autorun'
19
23
  require File.join(File.dirname(__FILE__), '..', 'lib', 'envyable')
20
24
 
21
25
  def destination_root(opts={})
22
- dir = File.join(File.dirname(__FILE__), "sandbox")
26
+ dir = File.join(File.dirname(__FILE__), 'sandbox')
23
27
  FileUtils.mkdir_p(dir)
24
28
  FileUtils.touch("#{dir}/.gitignore") if opts[:with_gitignore]
29
+ if opts[:with_spring_rb]
30
+ FileUtils.mkdir_p("#{dir}/config")
31
+ FileUtils.touch("#{dir}/config/spring.rb")
32
+ end
33
+ if opts[:with_spring_bin]
34
+ FileUtils.mkdir_p("#{dir}/bin")
35
+ FileUtils.touch("#{dir}/bin/spring")
36
+ end
25
37
  dir
26
38
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: envyable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Phil Nash
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-28 00:00:00.000000000 Z
11
+ date: 2016-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor