env_bang 0.4.1 → 1.0.0.pre.rc.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 40326b30460e728e3e5da019de6cfc93ae84b32c
4
- data.tar.gz: 3be97c644bcad37d63d69ec8314cef353596f1a2
2
+ SHA256:
3
+ metadata.gz: 9876284297bbe55660d78e4d62bb83ec54e40ec83ddc94ef56907020805945c1
4
+ data.tar.gz: 1ef016e91711a660eee17849a8ac28c1ba8d303e5d6a645415f66d51ab648fb6
5
5
  SHA512:
6
- metadata.gz: 2c43cd17a437cc0b8e6b2ecdc666cd19a9d5f989ba9dad8c51792ca50a9f6ade297df55761f50de2d47581d7b0b94f50afe21921934d5ceca4df759ff54027ad
7
- data.tar.gz: 5ce51c4a23064f9402672d56ef018ba2e10a056d972ff07830651ef6b2f976457390147fdbc11520ff55bf627811164bae37d92a285318499d401b1b68dcc275
6
+ metadata.gz: aa240511a3e7a4b4ea6437ec61f35fadbea111bfb191eeda6d25eee91818380cfc99d36a22734b48a66f945e53c3710e2909c9d4e132f64fb7df4c83bad1cdfc
7
+ data.tar.gz: d67dc205e27c91f1abe43b43d1745b432b6dfb2d9c495800c23b06a3e3616a89dabdde5513ce66d796074e346963b9fedb03f387fbb061fcea5e077efd557934
data/README.md CHANGED
@@ -1,11 +1,10 @@
1
- # ENV!
1
+ # ENV!
2
2
 
3
3
  Do a bang-up job managing your environment variables.
4
4
 
5
5
  [![Gem Version](https://img.shields.io/gem/v/env_bang.svg?style=flat)](https://rubygems.org/gems/env_bang)
6
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)
7
+ [![Maintainability](https://api.codeclimate.com/v1/badges/58ba2167873ed46687f9/maintainability)](https://codeclimate.com/github/jcamenisch/ENV_BANG/maintainability)
9
8
  [![Coverage Status](https://img.shields.io/coveralls/jcamenisch/ENV_BANG/master.svg?style=flat)](https://coveralls.io/r/jcamenisch/ENV_BANG)
10
9
 
11
10
  ENV! provides a thin wrapper around ENV to accomplish a few things:
@@ -202,7 +201,7 @@ ENV!['NUMBER_SET']
202
201
 
203
202
  ENV!.use :NUMBER_SET, class: Set
204
203
  ```
205
-
204
+
206
205
  While the `config` block is designed to provide a cleaner configuration
207
206
  file, calling the methods directly can occasionally be handy, such as when
208
207
  trying things out in an IRB/Pry session.
@@ -71,19 +71,42 @@ class ENV_BANG
71
71
  end
72
72
 
73
73
  def Date(value, options)
74
- require 'date'
75
74
  Date.parse(value)
76
75
  end
77
76
 
78
77
  def DateTime(value, options)
79
- require 'date'
80
78
  DateTime.parse(value)
81
79
  end
82
80
 
83
81
  def Time(value, options)
84
- require 'time'
85
82
  Time.parse(value)
86
83
  end
84
+
85
+ def Range(value, options = {})
86
+ beginning, ending = value.split('...')
87
+ if beginning && ending
88
+ options[:exclusive] = true unless options.has_key?(:exclusive)
89
+ else
90
+ beginning, ending = value.split('..')
91
+ end
92
+ unless beginning && ending
93
+ raise ArgumentError.new("Range '#{value}' cannot be parsed as a range. Must be in the form <start>..<end> or <start>...<end>")
94
+ end
95
+
96
+ options[:of] ||= Integer
97
+ beginning = cast(beginning, class: options[:of])
98
+ ending = cast(ending, class: options[:of])
99
+
100
+ if options[:exclusive]
101
+ beginning...ending
102
+ else
103
+ beginning..ending
104
+ end
105
+ end
106
+
107
+ def Regexp(value, options)
108
+ Regexp.new(value)
109
+ end
87
110
  end
88
111
  end
89
112
  end
@@ -1,3 +1,3 @@
1
1
  class ENV_BANG
2
- VERSION = "0.4.1"
2
+ VERSION = "1.0.0-rc.1"
3
3
  end
@@ -6,11 +6,19 @@ class ENV_BANG
6
6
  File.join(Rails.root.to_s, 'config/env.rb')
7
7
  end
8
8
 
9
+ def warn(msg)
10
+ if Rails.logger
11
+ Rails.logger.warn(msg)
12
+ else
13
+ puts "WARNING: #{msg}"
14
+ end
15
+ end
16
+
9
17
  config.before_configuration do
10
- if File.exists?(env_rb_file)
18
+ if File.exist?(env_rb_file)
11
19
  load env_rb_file
12
20
  else
13
- Rails.logger.warn "ENV! could not find your environment variable configuration. Please create #{env_rb_file} to set up environment variables at Rails boot."
21
+ warn("ENV! could not find your environment variable configuration. Please create #{env_rb_file} to set up environment variables at Rails boot.")
14
22
  end
15
23
  end
16
24
  end
@@ -190,6 +190,49 @@ describe ENV_BANG do
190
190
  ENV!['A_TIME'].must_equal Time.new(2005, 5, 5, 17, 5)
191
191
  end
192
192
 
193
+ it "casts Regexps" do
194
+ # Escaping backslashes is not without its pitfalls. Developer beware.
195
+ ENV['A_REGEX'] = '^(this|is|a|[^tes.*\|]t.\.\*/\\\)$'
196
+ ENV!.use 'A_REGEX', class: Regexp
197
+
198
+ ENV!['A_REGEX'].class.must_equal Regexp
199
+ ENV!['A_REGEX'].must_equal(/^(this|is|a|[^tes.*\|]t.\.\*\/\\)$/)
200
+ end
201
+
202
+ it "casts inclusive Ranges of Integers by default" do
203
+ ENV['A_RANGE'] = '1..100'
204
+ ENV!.use 'A_RANGE', class: Range
205
+
206
+ ENV!['A_RANGE'].class.must_equal Range
207
+ ENV!['A_RANGE'].must_equal 1..100
208
+ end
209
+
210
+ it "casts exclusive Ranges as directed" do
211
+ ENV['EXCLUSIVE_RANGE'] = '1..100'
212
+ ENV!.use 'EXCLUSIVE_RANGE', class: Range, exclusive: true
213
+
214
+ ENV!['EXCLUSIVE_RANGE'].must_equal 1...100
215
+
216
+ ENV['ANOTHER_EXCLUSIVE_RANGE'] = '1...100'
217
+ ENV!.use 'ANOTHER_EXCLUSIVE_RANGE', class: Range, exclusive: true
218
+
219
+ ENV!['ANOTHER_EXCLUSIVE_RANGE'].must_equal 1...100
220
+ end
221
+
222
+ it "casts Ranges of floats" do
223
+ ENV['FLOAT_RANGE'] = '1.5..100.7'
224
+ ENV!.use 'FLOAT_RANGE', class: Range, of: Float
225
+
226
+ ENV!['FLOAT_RANGE'].must_equal 1.5..100.7
227
+ end
228
+
229
+ it "casts Ranges of strings" do
230
+ ENV['FLOAT_RANGE'] = 'az..za'
231
+ ENV!.use 'FLOAT_RANGE', class: Range, of: String
232
+
233
+ ENV!['FLOAT_RANGE'].must_equal 'az'..'za'
234
+ end
235
+
193
236
  it "allows default class to be overridden" do
194
237
  ENV!.default_class.must_equal :StringUnlessFalsey
195
238
  ENV!.config { default_class String }
data/test/test_helper.rb CHANGED
@@ -3,7 +3,6 @@ require 'coveralls'
3
3
 
4
4
  require 'minitest/autorun'
5
5
  require 'minitest/spec'
6
- require 'minitest/pride'
7
6
 
8
7
  SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
9
8
  SimpleCov::Formatter::HTMLFormatter,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: env_bang
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 1.0.0.pre.rc.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Camenisch
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-22 00:00:00.000000000 Z
11
+ date: 2023-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -65,7 +65,7 @@ homepage: https://github.com/jcamenisch/ENV_BANG
65
65
  licenses:
66
66
  - MIT
67
67
  metadata: {}
68
- post_install_message:
68
+ post_install_message:
69
69
  rdoc_options: []
70
70
  require_paths:
71
71
  - lib
@@ -76,13 +76,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
76
76
  version: '0'
77
77
  required_rubygems_version: !ruby/object:Gem::Requirement
78
78
  requirements:
79
- - - ">="
79
+ - - ">"
80
80
  - !ruby/object:Gem::Version
81
- version: '0'
81
+ version: 1.3.1
82
82
  requirements: []
83
- rubyforge_project:
84
- rubygems_version: 2.2.5
85
- signing_key:
83
+ rubygems_version: 3.3.7
84
+ signing_key:
86
85
  specification_version: 4
87
86
  summary: Do a bang-up job managing your environment variables
88
87
  test_files: