nenv 0.0.2 → 0.0.3

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: 4aa66c0bda93185b1177fda8e93484e004f4e802
4
- data.tar.gz: 8b360b9cb96f49e49ade892326f1ab979ab4ab64
3
+ metadata.gz: bf78f1e4b9c0b4b0836dcb88c546d8d917506442
4
+ data.tar.gz: e18492bf894e4951f9e57bee5c343e507cbf7c06
5
5
  SHA512:
6
- metadata.gz: 872463708e4ba5ea45e565f5cf2de586900e702abd3996037388947f3e9e69da949e62d1a60dfa41550400427ee27e6cc8c736516f17278dc2a606903d7f81bb
7
- data.tar.gz: b793da1678ae9e09d164f0121286f6f35874c8721da2351aab457918188d086c318dcd84a75deaa67c9f7c1f270057275d26d5f02fabdf1929e1fe336c202882
6
+ metadata.gz: 2370b04d5e91d4817da56f343c36f0e94ababa43073316695c4f3e0f9365073f3031aca40956a4866d0e4b7a8ff6e790a6d3c9dee0596cabbbd56a820e1aa746
7
+ data.tar.gz: 23245f176a801613181ab0443aad7c1770d4cf879e83ba2cdbfdb392e0abf37a8a43013952a42d686a47de4c6f7cf57d8f71e9f0ab5a8ec2fdaa0ea1df2c608a
@@ -0,0 +1 @@
1
+ inherit_from: .rubocop_todo.yml
@@ -0,0 +1,33 @@
1
+ # This configuration was generated by `rubocop --auto-gen-config`
2
+ # on 2014-12-13 13:35:53 +0100 using RuboCop version 0.28.0.
3
+ # The point is for the user to remove these configuration records
4
+ # one by one as the offenses are removed from the code base.
5
+ # Note that changes in the inspected code, or installation of new
6
+ # versions of RuboCop, may require this file to be generated again.
7
+
8
+ # Offense count: 1
9
+ Lint/HandleExceptions:
10
+ Enabled: false
11
+
12
+ # Offense count: 1
13
+ Metrics/AbcSize:
14
+ Max: 16
15
+
16
+ # Offense count: 1
17
+ # Configuration parameters: AllowURI, URISchemes.
18
+ Metrics/LineLength:
19
+ Max: 112
20
+
21
+ # Offense count: 1
22
+ # Configuration parameters: CountComments.
23
+ Metrics/MethodLength:
24
+ Max: 11
25
+
26
+ # Offense count: 8
27
+ Style/Documentation:
28
+ Enabled: false
29
+
30
+ # Offense count: 1
31
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
32
+ Style/MethodName:
33
+ Enabled: false
@@ -0,0 +1,13 @@
1
+ language: ruby
2
+ bundler_args: --without development
3
+ rvm:
4
+ - 1.9.3
5
+ - 2.0.0
6
+ - 2.1.5
7
+ - ruby-head
8
+ - jruby
9
+ - rbx
10
+ matrix:
11
+ allow_failures:
12
+ - rvm: rbx
13
+ - rvm: jruby
data/Gemfile CHANGED
@@ -3,6 +3,9 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in nenv.gemspec
4
4
  gemspec development_group: :test
5
5
 
6
+ gem 'coveralls', require: false
7
+
6
8
  group :development do
7
- gem 'guard-rspec', '~> 4.5.0'
9
+ gem 'guard-rspec', '~> 4.5', require: false
10
+ gem 'guard-rubocop', require: false
8
11
  end
data/Guardfile CHANGED
@@ -7,28 +7,26 @@ directories(%w(lib spec))
7
7
  ## Uncomment to clear the screen before every task
8
8
  # clearing :on
9
9
 
10
- # Note: The cmd option is now required due to the increasing number of ways
11
- # rspec may be run, below are examples of the most common uses.
12
- # * bundler: 'bundle exec rspec'
13
- # * bundler binstubs: 'bin/rspec'
14
- # * spring: 'bin/rspec' (This will use spring if running and you have
15
- # installed the spring binstubs per the docs)
16
- # * zeus: 'zeus rspec' (requires the server to be started separately)
17
- # * 'just' rspec: 'rspec'
10
+ group :spec, halt_on_fail: true do
11
+ guard :rspec, cmd: 'bundle exec rspec' do
12
+ require 'guard/rspec/dsl'
13
+ dsl = Guard::RSpec::Dsl.new(self)
18
14
 
19
- guard :rspec, cmd: "bundle exec rspec" do
20
- require "guard/rspec/dsl"
21
- dsl = Guard::RSpec::Dsl.new(self)
15
+ # Feel free to open issues for suggestions and improvements
22
16
 
23
- # Feel free to open issues for suggestions and improvements
17
+ # RSpec files
18
+ rspec = dsl.rspec
19
+ watch(rspec.spec_helper) { rspec.spec_dir }
20
+ watch(rspec.spec_support) { rspec.spec_dir }
21
+ watch(rspec.spec_files)
24
22
 
25
- # RSpec files
26
- rspec = dsl.rspec
27
- watch(rspec.spec_helper) { rspec.spec_dir }
28
- watch(rspec.spec_support) { rspec.spec_dir }
29
- watch(rspec.spec_files)
23
+ # Ruby files
24
+ ruby = dsl.ruby
25
+ dsl.watch_spec_files_for(ruby.lib_files)
26
+ end
30
27
 
31
- # Ruby files
32
- ruby = dsl.ruby
33
- dsl.watch_spec_files_for(ruby.lib_files)
28
+ guard :rubocop do
29
+ watch(/.+\.rb$/)
30
+ watch(/(?:.+\/)?\.rubocop(?:_todo)?\.yml$/) { |m| File.dirname(m[0]) }
31
+ end
34
32
  end
data/README.md CHANGED
@@ -1,3 +1,9 @@
1
+ [![Build Status](https://travis-ci.org/e2/nenv.png?branch=master)](https://travis-ci.org/e2/nenv)
2
+ [![Gem Version](http://img.shields.io/gem/v/nenv.svg)](http://badge.fury.io/rb/nenv)
3
+ [![Dependency Status](https://gemnasium.com/e2/nenv.svg)](https://gemnasium.com/e2/nenv)
4
+ [![Code Climate](https://codeclimate.com/github/e2/nenv/badges/gpa.svg)](https://codeclimate.com/github/e2/nenv)
5
+ [![Coverage Status](https://coveralls.io/repos/e2/nenv/badge.png)](https://coveralls.io/r/e2/nenv)
6
+
1
7
  # Nenv
2
8
 
3
9
  Using ENV in Ruby is like using raw SQL statements - it feels wrong, because it is.
@@ -16,6 +22,10 @@ If you agree, this gem is for you.
16
22
  - strict mode saves you from doing validation yourself
17
23
  - and there's more to come...
18
24
 
25
+ Other benefits (and compared to other solutions):
26
+ - should still work with Ruby 1.8 (in case anyone is still stuck with it)
27
+ - it's designed to be as lightweight and as fast as possible compared to ENV
28
+ - designed to be both hackable and convenient
19
29
 
20
30
  ## Installation
21
31
 
@@ -42,6 +52,7 @@ Or install it yourself as:
42
52
  You no longer have to care whether the value is "0" or "false" or "no" or "FALSE" or ... whatever
43
53
 
44
54
  ```ruby
55
+ # Without Nenv
45
56
  t.verbose = (ENV['CI'] == 'true')
46
57
  ok = ENV['RUBYGEMS_GEMDEPS'] == "1" || ENV.key?('BUNDLE_GEMFILE']
47
58
  ENV['DEBUG'] = "true"
@@ -59,6 +70,7 @@ Nenv.debug = true
59
70
  ### "Namespaces"
60
71
 
61
72
  ```ruby
73
+ # Without Nenv
62
74
  puts ENV['GIT_BROWSER`]
63
75
  puts ENV['GIT_PAGER`]
64
76
  puts ENV['GIT_EDITOR`]
@@ -76,6 +88,7 @@ puts git.editor
76
88
  ### Custom type handling
77
89
 
78
90
  ```ruby
91
+ # Code without Nenv
79
92
  paths = [ENV['GEM_HOME`]] + ENV['GEM_PATH'].split(':')
80
93
  enable_logging if Integer(ENV['WEB_CONCURRENCY']) > 1
81
94
  mydata = YAML.load(ENV['MY_DATA'])
@@ -108,10 +121,10 @@ Nenv.verbose = debug
108
121
  ### Automatic conversion to string
109
122
 
110
123
  ```ruby
111
- ENV['RUBYGEMS_GEMDEPS'] = 1 # TypeError: no implicit conversion of Fixnum into String
124
+ ENV['RUBYGEMS_GEMDEPS'] = 1 # TypeError: no implicit conversion of Fixnum (...)
112
125
  ```
113
126
 
114
- No automatically uses `to_s`:
127
+ Nenv automatically uses `to_s`:
115
128
 
116
129
  ```ruby
117
130
  Nenv.rubygems_gemdeps = 1 # no problem here
@@ -129,7 +142,7 @@ ENV['MY_DATA'] = YAML.dump(data)
129
142
  can now become:
130
143
 
131
144
  ```ruby
132
- my = Nenv(:my)
145
+ my = Nenv :my
133
146
  my.instance.create_method(:data) { |d| YAML.load(d) }
134
147
  my.instance.create_method(:data=) { |d| YAML.dump(d) }
135
148
 
@@ -141,6 +154,7 @@ my.data = data
141
154
  ### Strict mode
142
155
 
143
156
  ```ruby
157
+ # Without Nenv
144
158
  fail 'home not allowed' if ENV['HOME'] = Dir.pwd # BUG! Assignment instead of comparing!
145
159
  puts ENV['HOME'] # Now contains clobbered value
146
160
  ```
@@ -172,6 +186,21 @@ Nenv.path += Pathname.pwd + "foo"
172
186
 
173
187
  ```
174
188
 
189
+ ### Your own class
190
+
191
+ ```ruby
192
+ class MyEnv < Nenv::Environment
193
+ def initialize
194
+ super("my_env")
195
+ create_method(:foo?)
196
+ end
197
+ end
198
+
199
+ MyEnv.new.foo? # same as ENV['MY_ENV_FOO'][/^(?:false|no|n|0)/i,1].nil?
200
+
201
+ ```
202
+
203
+
175
204
  ## NOTES
176
205
 
177
206
  Still, avoid using environment variables if you can.
@@ -196,13 +225,13 @@ Well sure, having ENV act like a Hash is much better than calling "getenv".
196
225
 
197
226
  Unfortunately, the advantages of using ENV make no sense:
198
227
 
199
- 1) it's faster but ... environment variables are rarely used thousands of times in tight loops
200
- 2) it's already an object ... but there's not much you can do with it
201
- 3) it's globally available ... but you can't isolate it in tests (you need to reset it every time)
202
- 4) you can use it to set variables ... but it's named like a const
203
- 5) it allows you to use keys regardless of case ... but by convention lowercase shouldn't be used except for local variables (which are only really used by shell scripts)
204
- 6) it's supposed to look ugly to discourage use ... but often your app/gem is forced to use them anyway
205
- 7) it's a simple class ... but either you encapsulate it in your own classes - or all the value mapping/validation happens everywhere you want the data
228
+ - it's faster but ... environment variables are rarely used thousands of times in tight loops
229
+ - it's already an object ... but there's not much you can do with it (try ENV.class)
230
+ - it's globally available ... but you can't isolate it in tests (you need to reset it every time)
231
+ - you can use it to set variables ... but it's named like a const
232
+ - it allows you to use keys regardless of case ... but by convention lowercase shouldn't be used except for local variables (which are only really used by shell scripts)
233
+ - it's supposed to look ugly to discourage use ... but often your app/gem is forced to use them anyway
234
+ - it's a simple class ... but either you encapsulate it in your own classes - or all the value mapping/validation happens everywhere you want the data (yuck!)
206
235
 
207
236
 
208
237
  But the BIGGEST disadvantage is in specs, e.g.:
data/Rakefile CHANGED
@@ -1,8 +1,17 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'nenv'
2
4
 
3
5
  default_tasks = []
4
6
 
5
- require "rspec/core/rake_task"
6
- default_tasks << RSpec::Core::RakeTask.new(:spec)
7
+ require 'rspec/core/rake_task'
8
+ default_tasks << RSpec::Core::RakeTask.new(:spec) do |t|
9
+ t.verbose = Nenv.ci?
10
+ end
11
+
12
+ unless Nenv.ci?
13
+ require 'rubocop/rake_task'
14
+ default_tasks << RuboCop::RakeTask.new(:rubocop)
15
+ end
7
16
 
8
17
  task default: default_tasks.map(&:name)
@@ -1,8 +1,8 @@
1
- require "nenv/version"
1
+ require 'nenv/version'
2
2
 
3
- require "nenv/autoenvironment"
3
+ require 'nenv/autoenvironment'
4
4
 
5
- def Nenv(namespace=nil)
5
+ def Nenv(namespace = nil)
6
6
  Nenv::AutoEnvironment.new(namespace)
7
7
  end
8
8
 
@@ -1,9 +1,9 @@
1
- require "nenv/environment"
1
+ require 'nenv/environment'
2
2
  module Nenv
3
3
  class AutoEnvironment < Nenv::Environment
4
4
  def method_missing(meth, *args)
5
5
  create_method(meth) unless respond_to?(meth)
6
- self.send(meth, *args)
6
+ send(meth, *args)
7
7
  end
8
8
  end
9
9
  end
@@ -1,5 +1,5 @@
1
- require "nenv/environment/dumper"
2
- require "nenv/environment/loader"
1
+ require 'nenv/environment/dumper'
2
+ require 'nenv/environment/loader'
3
3
 
4
4
  module Nenv
5
5
  class Environment
@@ -14,7 +14,7 @@ module Nenv
14
14
 
15
15
  class AlreadyExistsError < MethodError
16
16
  def message
17
- format("Method %s already exists", @meth.inspect)
17
+ format('Method %s already exists', @meth.inspect)
18
18
  end
19
19
  end
20
20
 
@@ -41,7 +41,7 @@ module Nenv
41
41
  private
42
42
 
43
43
  def _sanitize(meth)
44
- meth[/^([^=?]*)[=?]?$/, 1].upcase
44
+ meth.to_s[/^([^=?]*)[=?]?$/, 1].upcase
45
45
  end
46
46
  end
47
47
  end
@@ -2,7 +2,7 @@ module Nenv
2
2
  class Environment
3
3
  class Loader
4
4
  def initialize(meth)
5
- @bool = meth.to_s.end_with?("?")
5
+ @bool = meth.to_s.end_with?('?')
6
6
  end
7
7
 
8
8
  def load(raw_value, &callback)
@@ -16,9 +16,9 @@ module Nenv
16
16
  case raw_value
17
17
  when nil
18
18
  nil
19
- when ""
19
+ when ''
20
20
  fail ArgumentError, "Can't convert empty string into Bool"
21
- when "0", "false", "n", "no", "NO", "FALSE"
21
+ when '0', 'false', 'n', 'no', 'NO', 'FALSE'
22
22
  false
23
23
  else
24
24
  true
@@ -1,3 +1,3 @@
1
1
  module Nenv
2
- VERSION = "0.0.2"
2
+ VERSION = '0.0.3'
3
3
  end
@@ -4,21 +4,21 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'nenv/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "nenv"
7
+ spec.name = 'nenv'
8
8
  spec.version = Nenv::VERSION
9
- spec.authors = ["Cezary Baginski"]
10
- spec.email = ["cezary@chronomantic.net"]
11
- spec.summary = %q{Convenience wrapper for Ruby's ENV}
12
- spec.description = %q{Using ENV is like using raw SQL statements in your code. Well all know how that ends...}
13
- spec.homepage = ""
14
- spec.license = "MIT"
9
+ spec.authors = ['Cezary Baginski']
10
+ spec.email = ['cezary@chronomantic.net']
11
+ spec.summary = "Convenience wrapper for Ruby's ENV"
12
+ spec.description = 'Using ENV is like using raw SQL statements in your code. Well all know how that ends...'
13
+ spec.homepage = 'https://github.com/e2/nenv'
14
+ spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
17
+ spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(/^(test|spec|features)\//)
19
+ spec.require_paths = ['lib']
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.7"
22
- spec.add_development_dependency "rspec", "~> 3.1"
23
- spec.add_development_dependency "rake", "~> 10.0"
21
+ spec.add_development_dependency 'bundler', '~> 1.7'
22
+ spec.add_development_dependency 'rspec', '~> 3.1'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
24
  end
@@ -1,31 +1,31 @@
1
1
  require 'yaml'
2
2
 
3
- require "nenv/environment/dumper"
3
+ require 'nenv/environment/dumper'
4
4
 
5
5
  RSpec.describe Nenv::Environment::Dumper do
6
6
  subject { described_class.new.dump(value) }
7
7
 
8
8
  context "with \"abc\"" do
9
- let(:value) { "abc" }
10
- it { is_expected.to eq("abc") }
9
+ let(:value) { 'abc' }
10
+ it { is_expected.to eq('abc') }
11
11
  end
12
12
 
13
- context "with 123" do
13
+ context 'with 123' do
14
14
  let(:value) { 123 }
15
- it { is_expected.to eq("123") }
15
+ it { is_expected.to eq('123') }
16
16
  end
17
17
 
18
- context "with nil" do
18
+ context 'with nil' do
19
19
  let(:value) { nil }
20
20
  it { is_expected.to eq(nil) }
21
21
  end
22
22
 
23
- context "with a block" do
23
+ context 'with a block' do
24
24
  subject do
25
- described_class.new.dump(value) { |data| YAML::dump(data) }
25
+ described_class.new.dump(value) { |data| YAML.dump(data) }
26
26
  end
27
27
 
28
- context "with a yaml string" do
28
+ context 'with a yaml string' do
29
29
  let(:value) { { foo: 3 } }
30
30
  let(:yaml) { "---\n:foo: 3\n" }
31
31
  it { is_expected.to eq(yaml) }
@@ -1,20 +1,20 @@
1
1
  require 'yaml'
2
- require "nenv/environment/loader"
2
+ require 'nenv/environment/loader'
3
3
 
4
4
  RSpec.describe Nenv::Environment::Loader do
5
- context "with no block" do
5
+ context 'with no block' do
6
6
  subject { described_class.new(meth).load(value) }
7
7
 
8
- context "with a normal method" do
8
+ context 'with a normal method' do
9
9
  let(:meth) { :foo }
10
10
 
11
11
  context "with \"abc\"" do
12
- let(:value) { "abc" }
13
- it { is_expected.to eq("abc") }
12
+ let(:value) { 'abc' }
13
+ it { is_expected.to eq('abc') }
14
14
  end
15
15
  end
16
16
 
17
- context "with a bool method" do
17
+ context 'with a bool method' do
18
18
  let(:meth) { :foo? }
19
19
 
20
20
  %w(1 true y yes TRUE YES foobar).each do |data|
@@ -31,13 +31,13 @@ RSpec.describe Nenv::Environment::Loader do
31
31
  end
32
32
  end
33
33
 
34
- context "with nil" do
34
+ context 'with nil' do
35
35
  let(:value) { nil }
36
36
  it { is_expected.to eq(nil) }
37
37
  end
38
38
 
39
- context "when empty string" do
40
- let(:value) { "" }
39
+ context 'when empty string' do
40
+ let(:value) { '' }
41
41
  it do
42
42
  expect { subject }.to raise_error(
43
43
  ArgumentError, /Can't convert empty string into Bool/
@@ -47,13 +47,13 @@ RSpec.describe Nenv::Environment::Loader do
47
47
  end
48
48
  end
49
49
 
50
- context "with a block" do
50
+ context 'with a block' do
51
51
  subject do
52
- described_class.new(:foo).load(value) { |data| YAML::load(data) }
52
+ described_class.new(:foo).load(value) { |data| YAML.load(data) }
53
53
  end
54
- context "with a yaml string" do
54
+ context 'with a yaml string' do
55
55
  let(:value) { "--- foo\n...\n" }
56
- it { is_expected.to eq("foo") }
56
+ it { is_expected.to eq('foo') }
57
57
  end
58
58
  end
59
59
  end
@@ -1,13 +1,12 @@
1
- require "yaml"
1
+ require 'yaml'
2
2
 
3
- require "nenv/environment"
3
+ require 'nenv/environment'
4
4
 
5
5
  RSpec.describe Nenv::Environment do
6
6
  let(:env) { instance_double(Hash) } # a hash is close enough
7
- before(:each) { stub_const("ENV", env) }
8
-
9
- context "without integration" do
7
+ before(:each) { stub_const('ENV', env) }
10
8
 
9
+ context 'without integration' do
11
10
  let(:dumper) { instance_double(described_class::Dumper) }
12
11
  let(:loader) { instance_double(described_class::Loader) }
13
12
 
@@ -16,27 +15,27 @@ RSpec.describe Nenv::Environment do
16
15
  allow(described_class::Loader).to receive(:new).and_return(loader)
17
16
  end
18
17
 
19
- context "with no namespace" do
18
+ context 'with no namespace' do
20
19
  let(:instance) { described_class.new }
21
20
 
22
- context "with an existing method" do
21
+ context 'with an existing method' do
23
22
  before do
24
23
  subject.create_method(:foo?)
25
24
  end
26
25
 
27
- it "uses the name as full key" do
28
- expect(ENV).to receive(:[]).with("FOO").and_return("true")
29
- expect(loader).to receive(:load).with("true").and_return(true)
26
+ it 'uses the name as full key' do
27
+ expect(ENV).to receive(:[]).with('FOO').and_return('true')
28
+ expect(loader).to receive(:load).with('true').and_return(true)
30
29
  expect(subject.foo?).to eq(true)
31
30
  end
32
31
  end
33
32
  end
34
33
 
35
- context "with any namespace" do
36
- let(:namespace) { "bar" }
34
+ context 'with any namespace' do
35
+ let(:namespace) { 'bar' }
37
36
  let(:instance) { described_class.new(namespace) }
38
37
 
39
- describe "creating a method" do
38
+ describe 'creating a method' do
40
39
  subject { instance }
41
40
 
42
41
  before do
@@ -45,9 +44,9 @@ RSpec.describe Nenv::Environment do
45
44
 
46
45
  it { is_expected.to respond_to(:foo) }
47
46
 
48
- context "when the method already exists" do
47
+ context 'when the method already exists' do
49
48
  let(:error) { described_class::AlreadyExistsError }
50
- let(:message) { "Method :foo already exists" }
49
+ let(:message) { 'Method :foo already exists' }
51
50
  specify do
52
51
  expect do
53
52
  subject.create_method(:foo)
@@ -56,53 +55,52 @@ RSpec.describe Nenv::Environment do
56
55
  end
57
56
  end
58
57
 
59
- describe "calling" do
58
+ describe 'calling' do
60
59
  subject { instance }
61
60
 
62
- context "when method does not exist" do
61
+ context 'when method does not exist' do
63
62
  let(:error) { NoMethodError }
64
63
  let(:message) { /undefined method `foo' for/ }
65
64
  it { expect { subject.foo }.to raise_error(error, message) }
66
65
  end
67
66
 
68
- context "with a reader method" do
69
-
70
- context "with no block" do
67
+ context 'with a reader method' do
68
+ context 'with no block' do
71
69
  before { instance.create_method(meth) }
72
70
 
73
- context "with a normal method" do
71
+ context 'with a normal method' do
74
72
  let(:meth) { :foo }
75
73
  before do
76
- allow(loader).to receive(:load).with("123").and_return(123)
74
+ allow(loader).to receive(:load).with('123').and_return(123)
77
75
  end
78
76
 
79
- it "returns unmarshalled stored value" do
80
- expect(ENV).to receive(:[]).with("BAR_FOO").and_return("123")
77
+ it 'returns unmarshalled stored value' do
78
+ expect(ENV).to receive(:[]).with('BAR_FOO').and_return('123')
81
79
  expect(subject.foo).to eq 123
82
80
  end
83
81
  end
84
82
 
85
- context "with a bool method" do
83
+ context 'with a bool method' do
86
84
  let(:meth) { :foo? }
87
85
 
88
- it "references the proper ENV variable" do
89
- allow(loader).to receive(:load).with("false").and_return(false)
90
- expect(ENV).to receive(:[]).with("BAR_FOO").and_return("false")
86
+ it 'references the proper ENV variable' do
87
+ allow(loader).to receive(:load).with('false').and_return(false)
88
+ expect(ENV).to receive(:[]).with('BAR_FOO').and_return('false')
91
89
  expect(subject.foo?).to eq false
92
90
  end
93
91
  end
94
92
  end
95
93
 
96
- context "with a block" do
94
+ context 'with a block' do
97
95
  before do
98
- instance.create_method(:foo) { |data| YAML::load(data) }
96
+ instance.create_method(:foo) { |data| YAML.load(data) }
99
97
  end
100
98
 
101
99
  let(:value) { "---\n:foo: 5\n" }
102
100
 
103
- it "unmarshals using the block" do
104
- allow(ENV).to receive(:[]).with("BAR_FOO").
105
- and_return(value)
101
+ it 'unmarshals using the block' do
102
+ allow(ENV).to receive(:[]).with('BAR_FOO')
103
+ .and_return(value)
106
104
 
107
105
  allow(loader).to receive(:load).with(value) do |arg, &block|
108
106
  expect(block).to be
@@ -112,43 +110,42 @@ RSpec.describe Nenv::Environment do
112
110
  expect(subject.foo).to eq(foo: 5)
113
111
  end
114
112
  end
115
-
116
113
  end
117
114
 
118
- context "with a writer method" do
115
+ context 'with a writer method' do
119
116
  before { instance.create_method(:foo=) }
120
117
 
121
- it "set the environment variable" do
122
- expect(ENV).to receive(:[]=).with("BAR_FOO", "123")
123
- allow(dumper).to receive(:dump).with(123).and_return("123")
118
+ it 'set the environment variable' do
119
+ expect(ENV).to receive(:[]=).with('BAR_FOO', '123')
120
+ allow(dumper).to receive(:dump).with(123).and_return('123')
124
121
  subject.foo = 123
125
122
  end
126
123
 
127
- it "marshals and stores the value" do
128
- expect(ENV).to receive(:[]=).with("BAR_FOO", "123")
129
- allow(dumper).to receive(:dump).with(123).and_return("123")
124
+ it 'marshals and stores the value' do
125
+ expect(ENV).to receive(:[]=).with('BAR_FOO', '123')
126
+ allow(dumper).to receive(:dump).with(123).and_return('123')
130
127
  subject.foo = 123
131
128
  end
132
129
  end
133
130
 
134
- context "with a method containing underscores" do
131
+ context 'with a method containing underscores' do
135
132
  before { instance.create_method(:foo_baz) }
136
- it "reads the correct variable" do
137
- expect(ENV).to receive(:[]).with("BAR_FOO_BAZ").and_return("123")
138
- allow(loader).to receive(:load).with("123").and_return(123)
133
+ it 'reads the correct variable' do
134
+ expect(ENV).to receive(:[]).with('BAR_FOO_BAZ').and_return('123')
135
+ allow(loader).to receive(:load).with('123').and_return(123)
139
136
  subject.foo_baz
140
137
  end
141
138
  end
142
139
 
143
- context "with a block" do
140
+ context 'with a block' do
144
141
  before do
145
- instance.create_method(:foo=) { |data| YAML::dump(data) }
142
+ instance.create_method(:foo=) { |data| YAML.dump(data) }
146
143
  end
147
144
 
148
145
  let(:result) { "---\n:foo: 5\n" }
149
146
 
150
- it "marshals using the block" do
151
- allow(ENV).to receive(:[]=).with("BAR_FOO", result)
147
+ it 'marshals using the block' do
148
+ allow(ENV).to receive(:[]=).with('BAR_FOO', result)
152
149
 
153
150
  allow(dumper).to receive(:dump).with(foo: 5) do |arg, &block|
154
151
  expect(block).to be
@@ -159,60 +156,60 @@ RSpec.describe Nenv::Environment do
159
156
  end
160
157
  end
161
158
 
162
- context "with an unsanitized name" do
159
+ context 'with an unsanitized name' do
163
160
  pending
164
161
  end
165
162
  end
166
163
  end
167
164
  end
168
165
 
169
- describe "with integration" do
170
- context "with any namespace" do
171
- let(:namespace) { "baz" }
166
+ describe 'with integration' do
167
+ context 'with any namespace' do
168
+ let(:namespace) { 'baz' }
172
169
  let(:instance) { described_class.new(namespace) }
173
170
  subject { instance }
174
171
 
175
- context "with a reader method" do
176
- context "with no block" do
172
+ context 'with a reader method' do
173
+ context 'with no block' do
177
174
  before { instance.create_method(:foo) }
178
175
 
179
- it "returns the stored value" do
180
- allow(ENV).to receive(:[]).with("BAZ_FOO").and_return("123")
181
- expect(subject.foo).to eq "123"
176
+ it 'returns the stored value' do
177
+ allow(ENV).to receive(:[]).with('BAZ_FOO').and_return('123')
178
+ expect(subject.foo).to eq '123'
182
179
  end
183
180
  end
184
181
 
185
- context "with a block" do
182
+ context 'with a block' do
186
183
  before do
187
- instance.create_method(:foo) { |data| YAML::load(data) }
184
+ instance.create_method(:foo) { |data| YAML.load(data) }
188
185
  end
189
186
 
190
- it "unmarshals the value" do
191
- expect(ENV).to receive(:[]).with("BAZ_FOO").
192
- and_return("---\n:foo: 5\n")
187
+ it 'unmarshals the value' do
188
+ expect(ENV).to receive(:[]).with('BAZ_FOO')
189
+ .and_return("---\n:foo: 5\n")
193
190
 
194
191
  expect(subject.foo).to eq(foo: 5)
195
192
  end
196
193
  end
197
194
  end
198
195
 
199
- context "with a writer method" do
200
- context "with no block" do
196
+ context 'with a writer method' do
197
+ context 'with no block' do
201
198
  before { instance.create_method(:foo=) }
202
199
 
203
- it "marshals and stores the value" do
204
- expect(ENV).to receive(:[]=).with("BAZ_FOO", "123")
200
+ it 'marshals and stores the value' do
201
+ expect(ENV).to receive(:[]=).with('BAZ_FOO', '123')
205
202
  subject.foo = 123
206
203
  end
207
204
  end
208
205
 
209
- context "with a block" do
206
+ context 'with a block' do
210
207
  before do
211
- instance.create_method(:foo=) { |data| YAML::dump(data) }
208
+ instance.create_method(:foo=) { |data| YAML.dump(data) }
212
209
  end
213
210
 
214
- it "nmarshals the value" do
215
- expect(ENV).to receive(:[]=).with("BAZ_FOO", "---\n:foo: 5\n")
211
+ it 'nmarshals the value' do
212
+ expect(ENV).to receive(:[]=).with('BAZ_FOO', "---\n:foo: 5\n")
216
213
 
217
214
  subject.foo = { foo: 5 }
218
215
  end
@@ -1,51 +1,51 @@
1
- require "nenv"
1
+ require 'nenv'
2
2
 
3
3
  RSpec.describe Nenv do
4
4
  let(:env) { instance_double(Hash) } # Hash is close enough
5
- before { stub_const("ENV", env) }
5
+ before { stub_const('ENV', env) }
6
6
 
7
- describe "Nenv() helper method" do
8
- it "reads from env" do
7
+ describe 'Nenv() helper method' do
8
+ it 'reads from env' do
9
9
  expect(ENV).to receive(:[]).with('GIT_BROWSER').and_return('chrome')
10
10
  Nenv('git').browser
11
11
  end
12
12
 
13
- it "return the value from env" do
13
+ it 'return the value from env' do
14
14
  allow(ENV).to receive(:[]).with('GIT_BROWSER').and_return('firefox')
15
15
  expect(Nenv('git').browser).to eq('firefox')
16
16
  end
17
17
  end
18
18
 
19
- describe "Nenv() module" do
20
- it "reads from env" do
19
+ describe 'Nenv() module' do
20
+ it 'reads from env' do
21
21
  expect(ENV).to receive(:[]).with('CI').and_return('true')
22
22
  Nenv.ci?
23
23
  end
24
24
 
25
- it "return the value from env" do
25
+ it 'return the value from env' do
26
26
  allow(ENV).to receive(:[]).with('CI').and_return('false')
27
27
  expect(Nenv.ci?).to be(false)
28
28
  end
29
29
 
30
- context "with no method" do
31
- it "automatically creates the method" do
30
+ context 'with no method' do
31
+ it 'automatically creates the method' do
32
32
  expect(ENV).to receive(:[]).with('FOO').and_return('true')
33
33
  Nenv.foo?
34
34
  end
35
35
  end
36
36
 
37
- context "with existing method" do
37
+ context 'with existing method' do
38
38
  before do
39
39
  Nenv.instance.create_method(:foo?)
40
40
  end
41
41
 
42
- it "reads from env" do
43
- expect(ENV).to receive(:[]).with('FOO').and_return("true")
42
+ it 'reads from env' do
43
+ expect(ENV).to receive(:[]).with('FOO').and_return('true')
44
44
  Nenv.foo?
45
45
  end
46
46
 
47
- it "return the value from env" do
48
- expect(ENV).to receive(:[]).with('FOO').and_return("true")
47
+ it 'return the value from env' do
48
+ expect(ENV).to receive(:[]).with('FOO').and_return('true')
49
49
  expect(Nenv.foo?).to be(true)
50
50
  end
51
51
  end
@@ -1,3 +1,6 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
1
4
  RSpec.configure do |config|
2
5
  config.expect_with :rspec do |expectations|
3
6
  expectations.include_chain_clauses_in_custom_matcher_descriptions = true
@@ -14,9 +17,7 @@ RSpec.configure do |config|
14
17
 
15
18
  # config.warnings = true
16
19
 
17
- if config.files_to_run.one?
18
- config.default_formatter = 'doc'
19
- end
20
+ config.default_formatter = 'doc' if config.files_to_run.one?
20
21
 
21
22
  # config.profile_examples = 10
22
23
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nenv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cezary Baginski
@@ -62,6 +62,9 @@ extra_rdoc_files: []
62
62
  files:
63
63
  - ".gitignore"
64
64
  - ".rspec"
65
+ - ".rubocop.yml"
66
+ - ".rubocop_todo.yml"
67
+ - ".travis.yml"
65
68
  - Gemfile
66
69
  - Guardfile
67
70
  - LICENSE.txt
@@ -79,7 +82,7 @@ files:
79
82
  - spec/lib/nenv/environment_spec.rb
80
83
  - spec/lib/nenv_spec.rb
81
84
  - spec/spec_helper.rb
82
- homepage: ''
85
+ homepage: https://github.com/e2/nenv
83
86
  licenses:
84
87
  - MIT
85
88
  metadata: {}