nerv 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 939940d69234a709e2ff0b24d7dce91bca6cb6ef
4
+ data.tar.gz: 067e8d2aba86e3eff13a695d0ce4c8e8cc4c03a0
5
+ SHA512:
6
+ metadata.gz: 99950d864defa8e92c188239201e2357b3d4c68691ea9c8209e958f09021847908dc8325c2b9a8e4bccc504aa1ced5cc143470a8922759ea9c6fc68aef76f1bb
7
+ data.tar.gz: c0e45a3f6b8fe945320d47ce448d4c47b1f6134bc7c1d18e881cdf444bdc1fdc76db891b94be333ecc9be1cdc6648ceab2afa666be63d93a7d09210d01182d6e
@@ -0,0 +1,3 @@
1
+ lib/**/*.rb
2
+ -
3
+ LICENSE.txt
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ _yardoc
7
+ coverage
8
+ doc/
9
+ Gemfile.lock
10
+ InstalledFiles
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --order random
2
+ --color
3
+ -f d
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ rvm:
3
+ - ree
4
+ - 1.8.7
5
+ - 1.9.2
6
+ - 1.9.3
7
+ - ruby-head
8
+ - jruby-18mode
9
+ - jruby-19mode
10
+ - jruby-head
11
+ - rbx-18mode
12
+ - rbx-19mode
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in nerv.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Max Riveiro
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,61 @@
1
+ # Nerv - Environment Variables for Humans. Ruby Edition!
2
+
3
+ Nerv is a tiny gem, inspired by @kennethreitz [env](https://raw.github.com/kennethreitz/env/). So, it provides a mapping interface for Environment Variables, too.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'nerv'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install nerv
18
+
19
+ ## Usage
20
+
21
+ Let's assume that we have `ENV` like this:
22
+
23
+ ```ruby
24
+ ENV = {
25
+ 'RUBY_FREE_MIN' => 0,
26
+ 'RUBY_GC_MALLOC_LIMIT' => 0,
27
+ 'RBENV_SOME' => 0,
28
+ 'ZSH-HOME' => 0
29
+ }
30
+ ```
31
+
32
+ ```ruby
33
+ ruby_env = Nerv.prefix('RUBY')
34
+ # ruby_env == { 'FREE_MIN' => 0, 'GC_MALLOC_LIMIT' => 0 }
35
+ ```
36
+
37
+ `Nerv.prefix` has the second optional argument — a separator for ENV 'namespaces':
38
+
39
+ ```ruby
40
+ ruby_env = Nerv.prefix('ZSH', '-')
41
+ # ruby_env == { 'FREE_MIN' => 0, 'GC_MALLOC_LIMIT' => 0 }
42
+ ```
43
+
44
+ Also, there is a shorthand for `Nerv.prefix` with default separator:
45
+
46
+ ```ruby
47
+ ruby_env = Nerv['RUBY']
48
+ # ruby_env == { 'FREE_MIN' => 0, 'GC_MALLOC_LIMIT' => 0 }
49
+ ```
50
+
51
+ ## Contributing
52
+
53
+ 1. Fork it
54
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
55
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
56
+ 4. Push to the branch (`git push origin my-new-feature`)
57
+ 5. Create new Pull Request
58
+
59
+ ## Copyright
60
+
61
+ Copyright (c) 2013 Max Riveiro. See LICENSE.txt for further details.
@@ -0,0 +1,9 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'yard'
4
+
5
+ YARD::Rake::YardocTask.new
6
+
7
+ RSpec::Core::RakeTask.new('spec')
8
+
9
+ task :default => :spec
@@ -0,0 +1,21 @@
1
+ require 'nerv/version'
2
+
3
+ class Nerv
4
+ DEFAULT_SEPARATOR = '_'.freeze
5
+
6
+ class << self
7
+ def prefix(keys_prefix, separator = DEFAULT_SEPARATOR)
8
+ regexp = /^#{keys_prefix}#{separator}/
9
+
10
+ pairs = ENV.map { |k, v| [k.gsub(regexp, ''), v] if k =~ regexp }
11
+ .compact
12
+ .flatten
13
+
14
+ Hash[*pairs]
15
+ end
16
+
17
+ def [](keys_prefix)
18
+ prefix(keys_prefix)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ class Nerv
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'nerv/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'nerv'
8
+ spec.version = Nerv::VERSION
9
+ spec.authors = ['Max Riveiro']
10
+ spec.email = ['kavu13@gmail.com']
11
+ spec.description = %q{Nerv provides a mapping interface for Environment Variables}
12
+ spec.summary = %q{Environment Variables for Humans. Ruby Edition!}
13
+ spec.homepage = 'https://github.com/kavu/nerv'
14
+ spec.license = 'MIT'
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.test_files = spec.files.grep(%r{^spec/})
17
+ spec.require_paths = ['lib']
18
+
19
+ spec.add_development_dependency 'rake'
20
+ spec.add_development_dependency 'bundler', '~> 1.3'
21
+ spec.add_development_dependency 'rspec', '~> 2.13'
22
+ spec.add_development_dependency 'rspec-mocks', '~> 2.13'
23
+ spec.add_development_dependency 'yard', '~> 0.8.5'
24
+ end
@@ -0,0 +1,84 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ TEST_ENV = {
6
+ 'RUBY_FREE_MIN' => 0,
7
+ 'RUBY_GC_MALLOC_LIMIT' => 0,
8
+ 'RBENV_SOME' => 0,
9
+ 'ZSH-HOME' => 0
10
+ }.freeze
11
+
12
+ describe Nerv do
13
+ subject { Nerv }
14
+ it { should be_a Class }
15
+
16
+ describe '.prefix' do
17
+ describe 'with empty ENV' do
18
+ before { stub_const('ENV', {}) }
19
+
20
+ it 'returns proper empty Hash' do
21
+ Nerv.prefix('RUBY').should eql({})
22
+ end
23
+ end
24
+
25
+ describe 'with non-empty ENV' do
26
+ before { stub_const('ENV', TEST_ENV) }
27
+
28
+ describe 'with default separator' do
29
+ it 'returns proper prefix-processed Hash' do
30
+ expected = { 'FREE_MIN' => 0, 'GC_MALLOC_LIMIT' => 0 }
31
+ Nerv.prefix('RUBY').should eql(expected)
32
+
33
+ expected = { 'SOME' => 0 }
34
+ Nerv.prefix('RBENV').should eql(expected)
35
+ end
36
+ end
37
+
38
+ describe 'with custom separator' do
39
+ it 'returns proper prefix-processed Hash' do
40
+ expected = { 'HOME' => 0 }
41
+ Nerv.prefix('ZSH', '-').should eql(expected)
42
+ end
43
+ end
44
+
45
+ describe 'with non-existent prefix' do
46
+ it 'returns empty Hash' do
47
+ expected = {}
48
+ Nerv.prefix('GC').should eql(expected)
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ describe '.[]' do
55
+ describe 'with empty ENV' do
56
+ before { stub_const('ENV', {}) }
57
+
58
+ it 'returns proper empty Hash' do
59
+ Nerv['RUBY'].should eql({})
60
+ end
61
+ end
62
+
63
+ describe 'with non-empty ENV' do
64
+ before { stub_const('ENV', TEST_ENV) }
65
+
66
+ describe 'with default separator' do
67
+ it 'returns proper prefix-processed Hash' do
68
+ expected = { 'FREE_MIN' => 0, 'GC_MALLOC_LIMIT' => 0 }
69
+ Nerv['RUBY'].should eql(expected)
70
+
71
+ expected = { 'SOME' => 0 }
72
+ Nerv['RBENV'].should eql(expected)
73
+ end
74
+ end
75
+
76
+ describe 'with non-existent prefix' do
77
+ it 'returns empty Hash' do
78
+ expected = {}
79
+ Nerv['GC'].should eql(expected)
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,11 @@
1
+ # encoding: utf-8
2
+
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
+
6
+ require 'rspec'
7
+ require 'rspec/mocks'
8
+ require 'nerv'
9
+
10
+ RSpec.configure do |config|
11
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nerv
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Max Riveiro
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-03-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '2.13'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2.13'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-mocks
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.13'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '2.13'
69
+ - !ruby/object:Gem::Dependency
70
+ name: yard
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 0.8.5
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 0.8.5
83
+ description: Nerv provides a mapping interface for Environment Variables
84
+ email:
85
+ - kavu13@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .document
91
+ - .gitignore
92
+ - .rspec
93
+ - .travis.yml
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - lib/nerv.rb
99
+ - lib/nerv/version.rb
100
+ - nerv.gemspec
101
+ - spec/nerv_spec.rb
102
+ - spec/spec_helper.rb
103
+ homepage: https://github.com/kavu/nerv
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.0.3
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Environment Variables for Humans. Ruby Edition!
127
+ test_files:
128
+ - spec/nerv_spec.rb
129
+ - spec/spec_helper.rb
130
+ has_rdoc: