tiny_config 0.0.1 → 0.0.2

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
  SHA1:
3
- metadata.gz: 794a5639b058bc929497bb1ba97ba2f31289e48a
4
- data.tar.gz: ea0c7c8aa1a2725b458bf5f7872d5ed7bb6aa27d
3
+ metadata.gz: 47e176165b14b0b1001f0fda0390f8726d8e17e2
4
+ data.tar.gz: f782832b4521a906aab935dfb1878cd252cc38a7
5
5
  SHA512:
6
- metadata.gz: 7a6cedc44981cfb24c3b5a11b7fb24ad3beac6586ae3e1e3dfdfb0ad8268ae4eb2bdcaf03e7dec4689ad13103aa3a6a33d56c13f6ff37742042f141aaaff63bd
7
- data.tar.gz: 53fdf1e63fa519ba05b83ae6231a85ca555d4b54833b82f95f14330b15bc1f1704ba4ac3d9da897d5ea1ad667a8eecd7aa97562137e6bf85942271ec5370bec5
6
+ metadata.gz: 29004940958f153abf5201eb7af317c0d74dcb684102d7b4eaf19411c400dffc539c60fd080836aa26ace48d257e64c1bd14de60405d304715dd2106203c729a
7
+ data.tar.gz: cf9c8d084d55ab156a94cf57cc6afa5b7514331af56f8c142e39dd23d8f02c9626918b2e02e778fe7f08b398c167a4c316696ef3e46d04f0753ffd22f36a53cd
data/lib/tiny_config.rb CHANGED
@@ -13,14 +13,13 @@ class TinyConfig
13
13
 
14
14
  define_method config_key do
15
15
  v = instance_variable_get("@#{config_key}")
16
- v.nil? ? raise(TinyConfig::ConfigKeyNillError, message) : v
16
+ v.nil? ? raise(TinyConfig::ConfigKeyNillError, message(config_key)) : v
17
17
  end
18
18
  end
19
19
 
20
- def message
20
+ def message config_key
21
21
  namespace = self.class.to_s.split('::').last.downcase
22
- required_key = caller()[1].match(/`.*'?/).to_s.delete('`\'')
23
- "#{namespace} #{required_key} is requried."
22
+ "#{namespace} #{config_key} is requried."
24
23
  end
25
24
  }
26
25
  end
@@ -30,6 +29,10 @@ class TinyConfig
30
29
  const_get(namespace.capitalize).instance
31
30
  end
32
31
 
32
+ def self.clear!
33
+ constants.each { |c| remove_const(c) unless c =~ /Error$/ }
34
+ end
35
+
33
36
  class ConfigKeyNillError < StandardError; end
34
37
  class UndefinedNamespaceError < StandardError; end
35
38
  end
@@ -1,3 +1,3 @@
1
1
  class TinyConfig
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -35,4 +35,14 @@ describe TinyConfig, order: :defined do
35
35
  it { expect { TinyConfig.unregistered.key }.to raise_error TinyConfig::UndefinedNamespaceError }
36
36
  end
37
37
  end
38
+
39
+ context 'clear!' do
40
+ it 'deletes all const' do
41
+ TinyConfig.register(:config_d, :key)
42
+ TinyConfig.register(:config_e, :key)
43
+ TinyConfig.clear!
44
+ expect { TinyConfig.config_d.key }.to raise_error TinyConfig::UndefinedNamespaceError
45
+ expect { TinyConfig.config_e.key }.to raise_error TinyConfig::UndefinedNamespaceError
46
+ end
47
+ end
38
48
  end
data/tiny_config.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["gon.gong.gone@gmail.com"]
11
11
  spec.description = %q{simple and tiny config class for casual use}
12
12
  spec.summary = %q{simple and tiny config class}
13
- spec.homepage = "https://gong023.com/gong023/tiny_config"
13
+ spec.homepage = "https://github.com/gong023/tiny_config"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tiny_config
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - gong023
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-24 00:00:00.000000000 Z
11
+ date: 2014-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -71,7 +71,7 @@ files:
71
71
  - spec/spec_helper.rb
72
72
  - spec/tiny_config_spec.rb
73
73
  - tiny_config.gemspec
74
- homepage: https://gong023.com/gong023/tiny_config
74
+ homepage: https://github.com/gong023/tiny_config
75
75
  licenses:
76
76
  - MIT
77
77
  metadata: {}
@@ -98,4 +98,3 @@ summary: simple and tiny config class
98
98
  test_files:
99
99
  - spec/spec_helper.rb
100
100
  - spec/tiny_config_spec.rb
101
- has_rdoc: