env_bang 0.2.10 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 56076f21b1106dd3b9f43505dc300ccd27d09cdb
4
+ data.tar.gz: a8d957643766fbf0e01c3386fa8f91ff84dbaa17
5
+ SHA512:
6
+ metadata.gz: 3f0f5477d06e160baf27e3cd37c6c3837f7facf41d029fa82be8f8a427ad2629aab132f9f80bf0a9088718bef8be62c628072054b451ef3990da18c97864b96c
7
+ data.tar.gz: a06cf701db3d782c7cd8f528f9043b35fd72951da9b960ff7b8fd13fd0e5147ab5a117966c791c42727a0f10970c43421e410826c82b18090b681ddd259830fb
@@ -1,10 +1,4 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
4
3
  - 2.0.0
5
- - 2.1.0
6
- - ruby-head
7
- - jruby-19mode
8
- - jruby-head
9
- bundler_args: --without=guard
10
- cache: bundler
4
+ - 2.3.0
data/README.md CHANGED
@@ -1,13 +1,13 @@
1
- [![Gem Version](https://badge.fury.io/rb/env_bang.png)](https://rubygems.org/gems/env_bang)
2
- [![Build Status](https://secure.travis-ci.org/jcamenisch/ENV_BANG.png?branch=master)](https://travis-ci.org/jcamenisch/ENV_BANG)
3
- [![Dependency Status](https://gemnasium.com/jcamenisch/ENV_BANG.png)](https://gemnasium.com/jcamenisch/ENV_BANG)
4
- [![Code Climate](https://codeclimate.com/github/jcamenisch/ENV_BANG.png)](https://codeclimate.com/github/jcamenisch/ENV_BANG)
5
- [![Coverage Status](https://coveralls.io/repos/jcamenisch/ENV_BANG/badge.png?branch=master)](https://coveralls.io/r/jcamenisch/ENV_BANG)
6
-
7
1
  # ENV!
8
2
 
9
3
  Do a bang-up job managing your environment variables.
10
4
 
5
+ [![Gem Version](https://img.shields.io/gem/v/env_bang.svg?style=flat)](https://rubygems.org/gems/env_bang)
6
+ [![Build Status](https://img.shields.io/travis/jcamenisch/ENV_BANG/master.svg?style=flat)](https://travis-ci.org/jcamenisch/ENV_BANG)
7
+ [![Dependency Status](https://img.shields.io/gemnasium/jcamenisch/ENV_BANG.svg?style=flat)](https://gemnasium.com/jcamenisch/ENV_BANG)
8
+ [![Code Climate](https://img.shields.io/codeclimate/github/jcamenisch/ENV_BANG.svg?style=flat)](https://codeclimate.com/github/jcamenisch/ENV_BANG)
9
+ [![Coverage Status](https://img.shields.io/coveralls/jcamenisch/ENV_BANG/master.svg?style=flat)](https://coveralls.io/r/jcamenisch/ENV_BANG)
10
+
11
11
  ENV! provides a thin wrapper around ENV to accomplish a few things:
12
12
 
13
13
  - Provide a central place to specify all your app’s environment variables.
@@ -108,6 +108,7 @@ ENV!.config do
108
108
  use :MAIL_DELIVERY_METHOD, class: Symbol, default: :smtp
109
109
  use :DEFAULT_FRACTION, class: Float
110
110
  use :ENABLE_SOUNDTRACK, class: :boolean
111
+ use :PUPPETMASTERS, class: Hash
111
112
  end
112
113
  ```
113
114
 
@@ -120,6 +121,14 @@ ENV!.config do
120
121
  end
121
122
  ```
122
123
 
124
+ Hashes are split on commas (',') and key:value pairs are delimited by colon (':'). To get hashes of a specific type of value, use the `:of` option, and to use a different type for keys (default is `Symbol`), use the `:keys` option:
125
+
126
+ ```ruby
127
+ ENV!.config do
128
+ use :BIRTHDAYS, class: Hash, of: Integer, keys: String
129
+ end
130
+ ```
131
+
123
132
  #### Default type conversion behavior
124
133
 
125
134
  If you don’t specify a `:class` option for a variable, ENV! defaults to a special
@@ -20,6 +20,17 @@ class ENV_BANG
20
20
  value.split(',').map { |v| cast(v.strip, item_options) }
21
21
  end
22
22
 
23
+ def Hash(value, options)
24
+ key_options = options.merge(class: options.fetch(:keys, Symbol))
25
+ value_options = options.merge(class: options.fetch(:of, default_class))
26
+ {}.tap do |h|
27
+ value.split(',').each do |pair|
28
+ key, value = pair.split(':')
29
+ h[cast(key.strip, key_options)] = cast(value.strip, value_options)
30
+ end
31
+ end
32
+ end
33
+
23
34
  def Symbol(value, options)
24
35
  value.to_sym
25
36
  end
@@ -1,3 +1,3 @@
1
1
  class ENV_BANG
2
- VERSION = "0.2.10"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -99,6 +99,27 @@ describe ENV_BANG do
99
99
  end
100
100
  end
101
101
 
102
+ it "Casts Hashes" do
103
+ ENV['HASH'] = 'one: two, three: four'
104
+ ENV!.use 'HASH', class: Hash
105
+
106
+ ENV!['HASH'].must_equal({one: 'two', three: 'four'})
107
+ end
108
+
109
+ it 'Casts Hashes of Integers' do
110
+ ENV['INT_HASH'] = 'one: 111, two: 222'
111
+ ENV!.use 'INT_HASH', class: Hash, of: Integer
112
+
113
+ ENV!['INT_HASH'].must_equal({one: 111, two: 222})
114
+ end
115
+
116
+ it 'Casts Hashes with String keys' do
117
+ ENV['STRKEY_HASH'] = 'one: two, three: four'
118
+ ENV!.use 'STRKEY_HASH', class: Hash, keys: String
119
+
120
+ ENV!['STRKEY_HASH'].must_equal({'one' => 'two', 'three' => 'four'})
121
+ end
122
+
102
123
  it "Casts true" do
103
124
  ENV['TRUE'] = truthy_values.sample
104
125
  ENV!.use 'TRUE', class: :boolean
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: env_bang
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.10
5
- prerelease:
4
+ version: 0.3.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Jonathan Camenisch
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2015-02-20 00:00:00.000000000 Z
11
+ date: 2016-01-26 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ">="
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ">="
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: minitest
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - "~>"
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - "~>"
44
39
  - !ruby/object:Gem::Version
@@ -69,27 +64,26 @@ files:
69
64
  homepage: https://github.com/jcamenisch/ENV_BANG
70
65
  licenses:
71
66
  - MIT
67
+ metadata: {}
72
68
  post_install_message:
73
69
  rdoc_options: []
74
70
  require_paths:
75
71
  - lib
76
72
  required_ruby_version: !ruby/object:Gem::Requirement
77
- none: false
78
73
  requirements:
79
74
  - - ">="
80
75
  - !ruby/object:Gem::Version
81
76
  version: '0'
82
77
  required_rubygems_version: !ruby/object:Gem::Requirement
83
- none: false
84
78
  requirements:
85
79
  - - ">="
86
80
  - !ruby/object:Gem::Version
87
81
  version: '0'
88
82
  requirements: []
89
83
  rubyforge_project:
90
- rubygems_version: 1.8.24
84
+ rubygems_version: 2.2.5
91
85
  signing_key:
92
- specification_version: 3
86
+ specification_version: 4
93
87
  summary: Do a bang-up job managing your environment variables
94
88
  test_files:
95
89
  - test/env_bang_test.rb