constfig 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.0.4
2
+
3
+ - support for Array type
4
+
1
5
  # 0.0.3
2
6
 
3
7
  - fixed typos and added intro section to README
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
- ### Variable type
80
+ ### Type conversions
85
81
 
86
- One last thing. Non-string variables are supported. If you provide a non-string
87
- default (boolean, integer, float or symbol), the value that is coming from
88
- `ENV` will be converted to the same type (using `to_i`, `to_f`, and
89
- `to_symbol`). For the true/false types `"true"`, `"TRUE"`, and `"1"` will be
90
- treated as `true`, anything else will be treated as `false`.
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
@@ -24,6 +24,8 @@ module Constfig
24
24
 
25
25
  def convert_to_type(value, type)
26
26
  case type
27
+ when 'Array'
28
+ eval(value)
27
29
  when 'Fixnum'
28
30
  value.to_i
29
31
  when 'Float'
@@ -1,3 +1,3 @@
1
1
  module Constfig
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -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-05-26 00:00:00.000000000 Z
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: -4468990784169410071
52
- required_rubygems_version: !ruby/object:Gem::Requirement
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: -4468990784169410071
58
+ hash: -2939852624436089196
59
+ version: '0'
60
+ none: false
61
61
  requirements: []
62
62
  rubyforge_project:
63
63
  rubygems_version: 1.8.25