yamlcon 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -6
- data/lib/yamlcon/version.rb +1 -1
- data/lib/yamlcon/yaml_extension.rb +4 -0
- data/lib/yamlcon/yamlcon.rb +20 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e20cdf8184f40ac4e5f6d078b9b1acd2c901ae9
|
4
|
+
data.tar.gz: 63706b2369c60c78b3020516d1a91e3579c351cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b1cb5c6315d63fbcddf8d655becadbe8926f9a1356b5e74c3df6c41ad7b66225d33ed3ca13cf54f75bd844ad20f7f8e97d3c061e875d2911f4bf6b787fdbbaa
|
7
|
+
data.tar.gz: 101d8b064d920fcf5e13d06a709467c0e2da127a628ace46fcb4c6c4f46174db8a94b9ca78b7d810b51b56df646ad63dce168bcc3670778b70d7722eb58d9a58
|
data/README.md
CHANGED
@@ -1,7 +1,14 @@
|
|
1
|
-
YAML Config
|
1
|
+
YAMLCon - YAML Config Loader
|
2
2
|
==================================================
|
3
3
|
|
4
|
-
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/yamlcon.svg)](http://badge.fury.io/rb/yamlcon)
|
5
|
+
[![Build Status](https://travis-ci.org/DannyBen/yamlcon.svg?branch=master)](https://travis-ci.org/DannyBen/yamlcon)
|
6
|
+
[![Code Climate](https://codeclimate.com/github/DannyBen/yamlcon/badges/gpa.svg)](https://codeclimate.com/github/DannyBen/yamlcon)
|
7
|
+
[![Dependency Status](https://gemnasium.com/DannyBen/yamlcon.svg)](https://gemnasium.com/DannyBen/yamlcon)
|
8
|
+
|
9
|
+
--------------------------------------------------
|
10
|
+
|
11
|
+
A utility for loading and saving YAML files with dot.notation.
|
5
12
|
|
6
13
|
Install
|
7
14
|
--------------------------------------------------
|
@@ -9,16 +16,18 @@ Install
|
|
9
16
|
Add to your gemfile
|
10
17
|
|
11
18
|
```ruby
|
12
|
-
gem '
|
19
|
+
gem 'yamlcon'
|
13
20
|
```
|
14
21
|
|
15
22
|
Usage
|
16
23
|
--------------------------------------------------
|
17
24
|
|
18
25
|
```ruby
|
26
|
+
# Load
|
19
27
|
config = YAML.load_config 'path/to/config.yml'
|
20
28
|
puts config.any_option.or_nested
|
21
|
-
```
|
22
|
-
|
23
|
-
|
24
29
|
|
30
|
+
# Modify and save
|
31
|
+
config.some_setting = 'value'
|
32
|
+
YAML.save_config 'filename.yml', config
|
33
|
+
```
|
data/lib/yamlcon/version.rb
CHANGED
data/lib/yamlcon/yamlcon.rb
CHANGED
@@ -4,16 +4,32 @@ require 'ostruct'
|
|
4
4
|
module YAMLCon
|
5
5
|
def self.load_config(file)
|
6
6
|
hash = YAML.load_file file
|
7
|
-
|
7
|
+
hash_to_struct hash
|
8
8
|
end
|
9
9
|
|
10
|
-
|
10
|
+
def self.save_config(file, data)
|
11
|
+
File.open file, 'w' do |f|
|
12
|
+
f.write struct_to_yaml data
|
13
|
+
end
|
14
|
+
end
|
11
15
|
|
12
|
-
def self.
|
16
|
+
def self.hash_to_struct(hash)
|
13
17
|
dotted = OpenStruct.new hash
|
14
18
|
hash.each do |k, v|
|
15
|
-
dotted[k] =
|
19
|
+
dotted[k] = hash_to_struct(v) if v.is_a? Hash
|
16
20
|
end
|
17
21
|
dotted
|
18
22
|
end
|
23
|
+
|
24
|
+
def self.struct_to_hash(dot_notation)
|
25
|
+
hash = {}
|
26
|
+
dot_notation.each_pair do |k, v|
|
27
|
+
hash[k.to_s] = v.is_a?(OpenStruct) ? struct_to_hash(v) : v
|
28
|
+
end
|
29
|
+
hash
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.struct_to_yaml(dot_notation)
|
33
|
+
struct_to_hash(dot_notation).to_yaml
|
34
|
+
end
|
19
35
|
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.1.
|
4
|
+
version: 0.1.1
|
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-03-
|
11
|
+
date: 2016-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: runfile
|
@@ -72,5 +72,5 @@ rubyforge_project:
|
|
72
72
|
rubygems_version: 2.4.6
|
73
73
|
signing_key:
|
74
74
|
specification_version: 4
|
75
|
-
summary:
|
75
|
+
summary: YAML Config Loader
|
76
76
|
test_files: []
|