ensurable 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -7,4 +7,5 @@ pkg/*
7
7
  .yardoc
8
8
  /doc
9
9
  /coverage
10
+ .rvmrc
10
11
 
@@ -1,7 +1,7 @@
1
1
  Ensurable
2
2
  =========
3
3
 
4
- FYI this is very alpha software, also it's not meant to be used in production. Actually it aborts in production so...
4
+ FYI this is very alpha software, also it's not meant to be used in production. It just noops in production.
5
5
 
6
6
  Use Case
7
7
  -------
@@ -19,7 +19,7 @@ Installation
19
19
 
20
20
  In your Gemfile:
21
21
 
22
- gem 'ensurable'
22
+ gem 'ensurable', :group => [:development, :test]
23
23
 
24
24
  If you're using Rails you'll want to include this in your application.rb before the `require 'rails/all'`. This makes sure that this gem gets executed as early as possible and is able to ensure things before your app cries that it needs Msyql or Redis or something.
25
25
 
@@ -29,6 +29,8 @@ If you're using Rails you'll want to include this in your application.rb before
29
29
  require 'ensurable/now'
30
30
  require 'rails/all'
31
31
 
32
+ Otherwise if you're using Bundler you'll want to `require 'ensurable/now'` before Bundler.require for best results.
33
+
32
34
  Usage
33
35
  -----
34
36
 
@@ -13,11 +13,18 @@ module Ensurable
13
13
  # @yield optional block to allow any ensurables to be required
14
14
  def ensure(file = nil, &bloc)
15
15
  abortables = []
16
- abortables << (defined?(Rails) && Rails.respond_to?(:env) && Rails.env)
16
+
17
+ begin
18
+ abortables << Rails.env
19
+ rescue NameError, NoMethodError
20
+ end
17
21
  abortables << ENV['RAILS_ENV']
18
22
  abortables << ENV['RACK_ENV']
19
23
 
20
- abort('Ensurable is not meant for production use!') if abortables.any? {|a| a == 'production'}
24
+ if abortables.any? {|a| a == 'production'}
25
+ $stderr.puts("Ensurable gem is not meant for use in production, nooping.")
26
+ return
27
+ end
21
28
 
22
29
  if file
23
30
  instance_eval file.read
@@ -1,3 +1,3 @@
1
1
  module Ensurable
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,35 +1,35 @@
1
1
  require 'helper'
2
2
 
3
3
  class EnsurableTest < MiniTest::Unit::TestCase
4
- def test_aborts_if_rails_env_is_production
4
+ def test_noops_if_rails_env_is_production
5
5
  Rails.env = 'production'
6
6
 
7
- Ensurable.expects(:abort)
7
+ Ensurable.expects(:instance_eval).never
8
8
  Ensurable.ensure {}
9
9
 
10
10
  Rails.env = nil
11
11
  end
12
12
 
13
- def test_no_abort_if_rails_env_is_development
13
+ def test_works_if_rails_env_is_development
14
14
  Rails.env = 'development'
15
15
 
16
- Ensurable.expects(:abort).never
16
+ Ensurable.expects(:instance_eval)
17
17
  Ensurable.ensure {}
18
18
  end
19
19
 
20
- def test_abort_if_rails_env_var_is_production
20
+ def test_noop_if_rails_env_var_is_production
21
21
  ENV['RAILS_ENV'] = 'production'
22
22
 
23
- Ensurable.expects(:abort)
23
+ Ensurable.expects(:instance_eval).never
24
24
  Ensurable.ensure {}
25
25
 
26
26
  ENV['RAILS_ENV'] = nil
27
27
  end
28
28
 
29
- def test_abort_if_rack_env_var_is_production
29
+ def test_noop_if_rack_env_var_is_production
30
30
  ENV['RACK_ENV'] = 'production'
31
31
 
32
- Ensurable.expects(:abort)
32
+ Ensurable.expects(:instance_eval).never
33
33
  Ensurable.ensure {}
34
34
 
35
35
  ENV['RACK_ENV'] = nil
@@ -10,4 +10,6 @@ module Rails
10
10
  end
11
11
  end
12
12
 
13
+ # this will keep tests quiet that write to $stderr
14
+ $stderr = File.new('/dev/null', 'w')
13
15
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ensurable
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jesse Storimer
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-02 00:00:00 -05:00
18
+ date: 2011-02-03 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency