yamlcon 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +22 -6
- data/lib/yamlcon/version.rb +1 -1
- data/lib/yamlcon/yamlcon.rb +22 -4
- metadata +50 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 92e277d4e8098428ee2875233838c32e90d950d1
|
|
4
|
+
data.tar.gz: 2287e132b79af1926a42d513166f5c801425cade
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 813118ec6c7b20142233e4e17386d003e646d0bf8562f7c5efcf35098ddf29a477e7389d9f08e3fa107e301bbe1d1b7e63256849b374732352f171f6a3960b4d
|
|
7
|
+
data.tar.gz: 3d90efed5a51300c8160f06d5c37d648936d1131293eaa60aacc6b6d7eed8efce5dd7cc890eee1e28df4daaafc530dc7e96fd73aae7a48b1e38a5c2c8af82782
|
data/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
YAMLCon - YAML Config Loader
|
|
2
2
|
==================================================
|
|
3
3
|
|
|
4
|
-
[](https://rubygems.org/gems/yamlcon)
|
|
5
|
+
[](https://travis-ci.org/DannyBen/yamlcon)
|
|
6
|
+
[](https://codeclimate.com/github/DannyBen/yamlcon)
|
|
7
|
+
[](https://gemnasium.com/DannyBen/yamlcon)
|
|
8
8
|
|
|
9
9
|
--------------------------------------------------
|
|
10
10
|
|
|
@@ -22,12 +22,28 @@ gem 'yamlcon'
|
|
|
22
22
|
Usage
|
|
23
23
|
--------------------------------------------------
|
|
24
24
|
|
|
25
|
+
Load a single file
|
|
26
|
+
|
|
25
27
|
```ruby
|
|
26
|
-
# Load
|
|
27
28
|
config = YAML.load_config 'path/to/config.yml'
|
|
28
29
|
puts config.any_option.or_nested
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
You can then modify and save the file
|
|
29
33
|
|
|
30
|
-
|
|
34
|
+
```ruby
|
|
31
35
|
config.some_setting = 'value'
|
|
32
36
|
YAML.save_config 'filename.yml', config
|
|
33
37
|
```
|
|
38
|
+
|
|
39
|
+
Load multiple files by providing a glob pattern. In this case, each loaded
|
|
40
|
+
file will get its own prefix, using the basename of the file.
|
|
41
|
+
|
|
42
|
+
For example, given two files `config/one.yml` and `config/two.yml`, you can
|
|
43
|
+
do this:
|
|
44
|
+
|
|
45
|
+
```ruby
|
|
46
|
+
config = YAML.load_config 'config/*.yml'
|
|
47
|
+
puts config.one.option
|
|
48
|
+
puts config.two.option
|
|
49
|
+
```
|
data/lib/yamlcon/version.rb
CHANGED
data/lib/yamlcon/yamlcon.rb
CHANGED
|
@@ -2,9 +2,17 @@ require 'yaml'
|
|
|
2
2
|
require 'ostruct'
|
|
3
3
|
|
|
4
4
|
module YAMLCon
|
|
5
|
-
def self.load_config(
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
def self.load_config(path)
|
|
6
|
+
if path.include? "*"
|
|
7
|
+
result = OpenStruct.new
|
|
8
|
+
Dir[path].each do |file|
|
|
9
|
+
basename = File.basename(file).sub(/\..*/, '')
|
|
10
|
+
result[basename] = hash_to_struct YAML.load_file(file)
|
|
11
|
+
end
|
|
12
|
+
result
|
|
13
|
+
else
|
|
14
|
+
hash_to_struct YAML.load_file(path)
|
|
15
|
+
end
|
|
8
16
|
end
|
|
9
17
|
|
|
10
18
|
def self.save_config(file, data)
|
|
@@ -29,9 +37,19 @@ module YAMLCon
|
|
|
29
37
|
end
|
|
30
38
|
|
|
31
39
|
def self.struct_to_hash(dot_notation)
|
|
40
|
+
return dot_notation unless dot_notation.is_a? OpenStruct
|
|
41
|
+
|
|
32
42
|
hash = {}
|
|
33
43
|
dot_notation.each_pair do |k, v|
|
|
34
|
-
|
|
44
|
+
if v.is_a? OpenStruct
|
|
45
|
+
value = struct_to_hash(v)
|
|
46
|
+
elsif v.is_a? Array
|
|
47
|
+
value = v.map { |val| struct_to_hash val }
|
|
48
|
+
else
|
|
49
|
+
value = v
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
hash[k.to_s] = value
|
|
35
53
|
end
|
|
36
54
|
hash
|
|
37
55
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: yamlcon
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Danny Ben Shitrit
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-
|
|
11
|
+
date: 2016-05-31 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: runfile
|
|
@@ -16,28 +16,70 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '0.
|
|
19
|
+
version: '0.7'
|
|
20
20
|
type: :development
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
24
|
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '0.
|
|
26
|
+
version: '0.7'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
|
-
name:
|
|
28
|
+
name: runfile-tasks
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
30
30
|
requirements:
|
|
31
31
|
- - "~>"
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: '0.
|
|
33
|
+
version: '0.4'
|
|
34
34
|
type: :development
|
|
35
35
|
prerelease: false
|
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
37
|
requirements:
|
|
38
38
|
- - "~>"
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: '0.
|
|
40
|
+
version: '0.4'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rspec
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '3.4'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '3.4'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: byebug
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '9.0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '9.0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: simplecov
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0.11'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0.11'
|
|
41
83
|
description: Utility for easily loading YAML files as configuration objects
|
|
42
84
|
email: db@dannyben.com
|
|
43
85
|
executables: []
|
|
@@ -69,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
69
111
|
version: '0'
|
|
70
112
|
requirements: []
|
|
71
113
|
rubyforge_project:
|
|
72
|
-
rubygems_version: 2.
|
|
114
|
+
rubygems_version: 2.5.1
|
|
73
115
|
signing_key:
|
|
74
116
|
specification_version: 4
|
|
75
117
|
summary: YAML Config Loader
|