canfig 0.0.14 → 0.1.0

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: f5cf1818dc05ca85705475f4f667a025716f351f6c846b17ad2ca8d71ca94967
4
- data.tar.gz: 0b94d7c75bbb9e4cb443ee07094881af53b42dca689c5373fc28b04fb76f5fd9
3
+ metadata.gz: ef8277d97dee3f851bbc261e27c250272de6cc7fe862391918a9edb10a99b714
4
+ data.tar.gz: 85a61547bf9119ad5b31d3f1c488ac6bc7a6be8e945971444b7e3829cc2a29c7
5
5
  SHA512:
6
- metadata.gz: c07a4de23a58dffad06507b3dcadbae8c5ba77b24ab841a98ce1064c37b1caf55726502c9ca2d4abeab8ce753b7869b9aea52c316ce5309a972d15673ea973e3
7
- data.tar.gz: 3e7ac47e76ece7eb4311fbca9b3786ba445a6ed59b4e520aaaf44350f567c5c420762f7770bd2dc78e9d8f5a43c614d154ed9a6c37bf3a56305a649cd881f4bb
6
+ metadata.gz: 1c5d4e0a71d5e8a3923f51229c7e925895f80cd3dce206528b6cdad4090ee548a1aad874098ecd8b5526f7bacf27d8cfae706422d64528447eaa274dba71db61
7
+ data.tar.gz: 5628f2e515406cbb1362a36d54dc7b6b67118c350e2b6276ca104ac8115a2449ac4426aba2a18651112449adc7fc93a48c1ff1d6e4f2e9a1ff792e5866d96f4b
data/lib/canfig/config.rb CHANGED
@@ -28,16 +28,26 @@ module Canfig
28
28
  end
29
29
  end
30
30
 
31
+ def thread_configs
32
+ Thread.current[:_canfig_configs] ||= {}
33
+ Thread.current[:_canfig_configs]
34
+ end
35
+
36
+ def state
37
+ thread_configs[object_id] ||= {}
38
+ thread_configs[object_id]
39
+ end
40
+
31
41
  def set(key, val)
32
42
  raise NoMethodError, "undefined method `#{key.to_s}=' for #{self.to_s}" unless allowed?(key)
33
43
 
34
44
  save_state! do
35
- @state[key] = val
45
+ state[key] = val
36
46
  end
37
47
  end
38
48
 
39
49
  def env(key, default=nil, &block)
40
- @state[key] ||= begin
50
+ state[key] ||= begin
41
51
  val = ENV.fetch(key.to_s.underscore.upcase, default, &block)
42
52
  val = default if val.blank?
43
53
  val = env(val, default, &block) if val && ENV.key?(val.to_s)
@@ -48,7 +58,7 @@ module Canfig
48
58
 
49
59
  def clear(*keys)
50
60
  save_state! do
51
- keys.each { |key| @state[key] = nil }
61
+ keys.each { |key| state[key] = nil }
52
62
  end
53
63
  end
54
64
 
@@ -58,7 +68,7 @@ module Canfig
58
68
 
59
69
  def get(key, default=nil, &block)
60
70
  raise NoMethodError, "undefined method `#{key.to_s}' for #{self.to_s}" unless allowed?(key)
61
- @state[key] || (block_given? ? yield : default)
71
+ state[key] || (block_given? ? yield : default)
62
72
  end
63
73
 
64
74
  def [](key)
@@ -66,11 +76,11 @@ module Canfig
66
76
  end
67
77
 
68
78
  def to_h
69
- Hash[@allowed.map { |key| [key, @state[key]] }]
79
+ Hash[@allowed.map { |key| [key, state[key]] }]
70
80
  end
71
81
 
72
82
  def changed
73
- Hash[@allowed.map { |key| [key, [@saved_state[key], @state[key]]] if @saved_state[key] != @state[key] }.compact]
83
+ Hash[@allowed.map { |key| [key, [@saved_state[key], state[key]]] if @saved_state[key] != state[key] }.compact]
74
84
  end
75
85
 
76
86
  def changed?(key)
@@ -125,7 +135,6 @@ module Canfig
125
135
 
126
136
  def initialize(*args, **options, &block)
127
137
  @allowed = (args.map(&:to_sym) + options.symbolize_keys.keys).uniq
128
- @state = {}
129
138
  enable_state_saves!
130
139
  configure options, &block
131
140
  end
@@ -1,3 +1,3 @@
1
1
  module Canfig
2
- VERSION = '0.0.14'
2
+ VERSION = '0.1.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: canfig
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Rebec
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-01 00:00:00.000000000 Z
11
+ date: 2021-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -77,7 +77,7 @@ files:
77
77
  homepage: http://github.com/markrebec/canfig
78
78
  licenses: []
79
79
  metadata: {}
80
- post_install_message:
80
+ post_install_message:
81
81
  rdoc_options: []
82
82
  require_paths:
83
83
  - lib
@@ -93,13 +93,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
93
  version: '0'
94
94
  requirements: []
95
95
  rubygems_version: 3.1.2
96
- signing_key:
96
+ signing_key:
97
97
  specification_version: 4
98
98
  summary: Dead simple canned configuration for gems or whatever
99
99
  test_files:
100
- - spec/spec_helper.rb
101
- - spec/fixtures/config.yml
102
- - spec/canfig/config_spec.rb
103
100
  - spec/canfig/open_config_spec.rb
104
101
  - spec/canfig/yaml_spec.rb
102
+ - spec/canfig/config_spec.rb
103
+ - spec/fixtures/config.yml
104
+ - spec/spec_helper.rb
105
105
  - spec/canfig_spec.rb