constfig 0.0.3 → 0.0.4
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.
- data/CHANGELOG +4 -0
- data/README.md +9 -10
- data/lib/constfig/config.rb +2 -0
- data/lib/constfig/version.rb +1 -1
- data/spec/constfig/constfig_spec.rb +2 -0
- metadata +8 -8
data/CHANGELOG
CHANGED
data/README.md
CHANGED
@@ -40,10 +40,6 @@ allows you to do just that, have a configuration parameters stored in constants
|
|
40
40
|
with values coming from environment variables and ability to provide defaults
|
41
41
|
or have required parameters (i.e. fail if missing).
|
42
42
|
|
43
|
-
I just released version 0.0.1 of [constfig](https://rubygems.org/gems/constfig)
|
44
|
-
to rubygems. Sources are of course on
|
45
|
-
[github](https://github.com/astrails/constfig).
|
46
|
-
|
47
43
|
## Installation
|
48
44
|
|
49
45
|
Add this line to your application's Gemfile:
|
@@ -81,13 +77,13 @@ Or you can call it without the default:
|
|
81
77
|
In which case it will raise exception `Constfig::Undefined` if
|
82
78
|
`ENV['DEFAULT_DOMAIN']` is not available.
|
83
79
|
|
84
|
-
###
|
80
|
+
### Type conversions
|
85
81
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
82
|
+
Non-string variables are supported. If you provide a non-string default
|
83
|
+
(boolean, integer, float or symbol), the value that is coming from `ENV` will
|
84
|
+
be converted to the same type (using `to_i`, `to_f`, and `to_symbol`). For the
|
85
|
+
true/false types `"true"`, `"TRUE"`, and `"1"` will be treated as `true`,
|
86
|
+
anything else will be treated as `false`.
|
91
87
|
|
92
88
|
In the case of required variables, you can supply a `Class` in place of the
|
93
89
|
default, and it will be used for the type conversion. Like this:
|
@@ -96,6 +92,9 @@ default, and it will be used for the type conversion. Like this:
|
|
96
92
|
|
97
93
|
For boolean variables you can supply either `TrueClass`, or `FalseClass`.
|
98
94
|
|
95
|
+
There is a special case for `Array`, e.i. when either default value is an array,
|
96
|
+
or `Array` is passed as type. In this case the value is just passed to `eval`.
|
97
|
+
|
99
98
|
### Existing constants
|
100
99
|
|
101
100
|
This gem will not re-define existing constants, which can be used to define
|
data/lib/constfig/config.rb
CHANGED
data/lib/constfig/version.rb
CHANGED
@@ -55,6 +55,7 @@ describe Constfig do
|
|
55
55
|
verify_conversion '1', true, true
|
56
56
|
verify_conversion 'true', true, true
|
57
57
|
verify_conversion 'TRUE', true, true
|
58
|
+
verify_conversion '[1,2,3]', [], [1,2,3]
|
58
59
|
|
59
60
|
verify_conversion '12.3', Fixnum, 12
|
60
61
|
verify_conversion '12.3', Float, 12.3
|
@@ -70,6 +71,7 @@ describe Constfig do
|
|
70
71
|
verify_conversion 'true', FalseClass, true
|
71
72
|
verify_conversion 'TRUE', TrueClass, true
|
72
73
|
verify_conversion 'TRUE', FalseClass, true
|
74
|
+
verify_conversion '[1,2,"123"]', Array, [1,2,"123"]
|
73
75
|
end
|
74
76
|
|
75
77
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: constfig
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.3
|
5
4
|
prerelease:
|
5
|
+
version: 0.0.4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Vitaly Kushner
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-08-27 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Simple Constnt Configuration for Ruby. Allows you to define configuration
|
15
15
|
CONSTANTS that take values from environment variables. With support for default
|
@@ -41,23 +41,23 @@ rdoc_options: []
|
|
41
41
|
require_paths:
|
42
42
|
- lib
|
43
43
|
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
-
none: false
|
45
44
|
requirements:
|
46
45
|
- - ! '>='
|
47
46
|
- !ruby/object:Gem::Version
|
48
|
-
version: '0'
|
49
47
|
segments:
|
50
48
|
- 0
|
51
|
-
hash: -
|
52
|
-
|
49
|
+
hash: -2939852624436089196
|
50
|
+
version: '0'
|
53
51
|
none: false
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
53
|
requirements:
|
55
54
|
- - ! '>='
|
56
55
|
- !ruby/object:Gem::Version
|
57
|
-
version: '0'
|
58
56
|
segments:
|
59
57
|
- 0
|
60
|
-
hash: -
|
58
|
+
hash: -2939852624436089196
|
59
|
+
version: '0'
|
60
|
+
none: false
|
61
61
|
requirements: []
|
62
62
|
rubyforge_project:
|
63
63
|
rubygems_version: 1.8.25
|