canfig 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 28a747df13cf5c6c99fa96a201cb5f300b707a4642a63e5a65a943582a1fdde5
4
- data.tar.gz: c917be14d97451e7615943952729ce00cc03b322c62536249a9a5859c88c63d0
3
+ metadata.gz: cb0af652bc6aced0a5a7be703c93267bbef555c28f821c565c9c5b14f93b6d20
4
+ data.tar.gz: cb3541d3ca774f5f7a331f75238ecef6231b62be3776b50ae52cac3b12182c6b
5
5
  SHA512:
6
- metadata.gz: 4cf03ffeb05d41a42ef388d42013000cc62402befb390b1c188ac8a0acdda9c3e04fea5c63d47dd103258cedc5d36c9ce0d31ef14c079abbbd4842f4d5520589
7
- data.tar.gz: 006e3e970b3aec9905abaa038bfca1f470f8b80ce6f8f2c743a729ebbf956d3a08425708d9aa0b486da58b6ea44178c69219c860edf40226bd999606d771aa1d
6
+ metadata.gz: aab3a3c345efea85b20c75e8aec11ccd62baab19e8dcfa5b5870406a2731e6894311a21273b10cfea3476f037185b300e862e027a19bf8314fbb9300054d2b78
7
+ data.tar.gz: ebc54005799b649dbecc527bd30f6bbad0149ad4fc022b2998323b0fe6b7888df12ffc1050a9884caee2ee14e30093f315408ed08e657b4e3a8dc657e3449459
@@ -5,6 +5,7 @@ require 'canfig/version'
5
5
  require 'canfig/yaml'
6
6
  require 'canfig/config'
7
7
  require 'canfig/open_config'
8
+ require 'canfig/env_config'
8
9
  require 'canfig/module'
9
10
  require 'canfig/class'
10
11
  require 'canfig/instance'
@@ -41,9 +41,9 @@ module Canfig
41
41
  val && ENV.key?(val) ? env(val, default, &block) : val
42
42
  end
43
43
 
44
- def clear(key)
44
+ def clear(*keys)
45
45
  save_state! do
46
- @state[key] = nil
46
+ keys.each { |key| @state[key] = nil }
47
47
  end
48
48
  end
49
49
 
@@ -118,8 +118,7 @@ module Canfig
118
118
 
119
119
  protected
120
120
 
121
- def initialize(*args, &block)
122
- options = args.extract_options!
121
+ def initialize(*args, **options, &block)
123
122
  @allowed = (args.map(&:to_sym) + options.symbolize_keys.keys).uniq
124
123
  @state = {}
125
124
  enable_state_saves!
@@ -0,0 +1,20 @@
1
+ module Canfig
2
+ class EnvConfig < OpenConfig
3
+ attr_reader :namespace
4
+
5
+ def initialize(namespace=nil, **options, &block)
6
+ @namespace = namespace ? "#{namespace.to_s.underscore.upcase.gsub(/_$/, '')}_" : namespace
7
+ super(**options, &block)
8
+ end
9
+
10
+ def set(key, val)
11
+ raise NotImplementedError, "You cannot set values on a Canfig::EnvConfig"
12
+ end
13
+
14
+ def env(key, default=nil, &block)
15
+ key = key.to_s.underscore.upcase
16
+ key = key.gsub(/^#{namespace}/, '') if namespace
17
+ super("#{namespace}#{key}", default, &block)
18
+ end
19
+ end
20
+ end
@@ -1,8 +1,8 @@
1
1
  module Canfig
2
2
  class OpenConfig < Config
3
3
  def set(key, val)
4
- super(key, val)
5
4
  @allowed << key unless @allowed.include?(key)
5
+ super(key, val)
6
6
  end
7
7
 
8
8
  def allowed?(opt)
@@ -1,3 +1,3 @@
1
1
  module Canfig
2
- VERSION = '0.0.8'
2
+ VERSION = '0.0.9'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: canfig
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Rebec
@@ -62,6 +62,7 @@ files:
62
62
  - lib/canfig.rb
63
63
  - lib/canfig/class.rb
64
64
  - lib/canfig/config.rb
65
+ - lib/canfig/env_config.rb
65
66
  - lib/canfig/instance.rb
66
67
  - lib/canfig/module.rb
67
68
  - lib/canfig/open_config.rb