sb-config 0.1.0 → 0.2.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: 95fafd867a36c8ecf92923e26fddd73d87b981e1ea9d2d3271ac83e46604e4de
4
- data.tar.gz: 6b6384fd0d7cc6fd03419ccf65acfa73a88299dbd41704b1f8cb50a4b8f26c2d
3
+ metadata.gz: 777e42fd6adb45e6c539485b8c81e8b5f3b12d15c61abd2555b4bb977468c88e
4
+ data.tar.gz: 04c66358c5aed1f2b67acab86f8f82c1fb79311e1b82f68f7d41aa016948524e
5
5
  SHA512:
6
- metadata.gz: 826fcc7cf83fe0b1306c1d6760fd3e4ae9a8219bec4cc598abdd17f3a5f6c12105d1e682ccdca32c8aaaef753e2f2afa24b9b426c32d99fd052abdea8ccbe5f4
7
- data.tar.gz: d38c2c73a9cb350e3365533d5b3502e635bb28f67f37b3e4fb089eb1f2eec0e834926e020521ad7e6531f4b87727510c79bbf94fc8f358ff71e3ae799a51a1ae
6
+ metadata.gz: 46b7748b98b6dce7d3cb58ec744e5483361826c7804e1fc26d191ae82b0c7e6ce51c141a4e37f016988acfcd8d6333bc1830d476729b7098b2ec00aeb6636b71
7
+ data.tar.gz: 7e2d425e3dd4e92dd5f82b0af4c8e4232ec4315b624406322b1f2078c7cc6648f4023779bcfee50c0b28d60c64604c3f5e71f759c0aa95b83a58a9a1d0021abf
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
 
3
+ gem 'yaml'
4
+ gem 'json'
3
5
  # Specify your gem's dependencies in config.gemspec
4
6
  gemspec
@@ -1,20 +1,24 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- config (0.1.0)
4
+ sb-config (0.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
+ json (2.3.0)
9
10
  rake (10.5.0)
11
+ yaml (0.1.0)
10
12
 
11
13
  PLATFORMS
12
14
  ruby
13
15
 
14
16
  DEPENDENCIES
15
17
  bundler (~> 2.0)
16
- config!
18
+ json
17
19
  rake (~> 10.0)
20
+ sb-config!
21
+ yaml
18
22
 
19
23
  BUNDLED WITH
20
24
  2.0.2
data/bin/config CHANGED
@@ -3,15 +3,5 @@
3
3
  require "bundler/setup"
4
4
  require "config"
5
5
 
6
- Config.store = {
7
- 'one' => 1,
8
- 'two' => 2,
9
- 'three' => {
10
- 'n' => 3
11
- }
12
- }
13
-
14
- puts Config.store
15
- puts Config['one']
16
- puts Config.store
17
- puts Config['three']['n']
6
+ Config.load './test/c.yaml'
7
+ puts Config.store
@@ -29,4 +29,6 @@ Gem::Specification.new do |spec|
29
29
 
30
30
  spec.add_development_dependency "bundler", "~> 2.0"
31
31
  spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "json", "~> 2.3.0"
33
+ spec.add_development_dependency "yaml", "~> 3.0.3"
32
34
  end
@@ -1,3 +1,5 @@
1
+ require 'yaml'
2
+ require 'json'
1
3
  require "config/version"
2
4
 
3
5
  module Config
@@ -9,6 +11,19 @@ module Config
9
11
 
10
12
  @@store = {}
11
13
 
14
+ def self.load path, type=nil
15
+ # infer type if nil
16
+
17
+ fmt = path.split('.').last
18
+ fmt ||= type
19
+
20
+ if fmt.nil?
21
+ return false
22
+ end
23
+
24
+ @@store = send("load_#{fmt}", path)
25
+ end
26
+
12
27
  def self.store=(v)
13
28
  @@store = v if v.is_a? Hash
14
29
  end
@@ -20,4 +35,15 @@ module Config
20
35
  def self.[](k)
21
36
  @@store[k]
22
37
  end
38
+
39
+ private
40
+ def self.load_yaml path
41
+ YAML.load_file path
42
+ end
43
+
44
+ def self.load_json path
45
+ c = File.read path
46
+ puts c
47
+ JSON.parse c
48
+ end
23
49
  end
@@ -1,3 +1,3 @@
1
1
  module Config
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sb-config
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - iodevel
@@ -38,6 +38,34 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 2.3.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 2.3.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: yaml
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 3.0.3
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 3.0.3
41
69
  description:
42
70
  email:
43
71
  - cbrandt92@gmail.com