yamlcon 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c46897559fdbfb770370cb47657073f5cfa877f9
4
- data.tar.gz: 25ea9362bd0bf4cb4cfed57454714532d83fad76
3
+ metadata.gz: 4e20cdf8184f40ac4e5f6d078b9b1acd2c901ae9
4
+ data.tar.gz: 63706b2369c60c78b3020516d1a91e3579c351cc
5
5
  SHA512:
6
- metadata.gz: 977eb592f33dafd30b0b06f5c5a62f57f97b235e1c4646540dd493be547d9bc675837b87f71e1177df76619563350154714fbe57b24ce84dba2fa492f0eec53a
7
- data.tar.gz: 03958b5a6bb763a419599a22db4ee95f05010ae5f1c9ce2fdae0343895a647a27836b6db680eb7793bc74e7e3fe52006ac284a029bc6552743aa5513063022e4
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
- A utility for loading YAML files as first class configuration objects.
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 'yaml_conf'
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
+ ```
@@ -1,3 +1,3 @@
1
1
  module YAMLCon
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -4,4 +4,8 @@ module YAML
4
4
  def self.load_config(file)
5
5
  YAMLCon.load_config file
6
6
  end
7
+
8
+ def self.save_config(file, data)
9
+ YAMLCon.save_config file, data
10
+ end
7
11
  end
@@ -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
- dot_notation_from hash
7
+ hash_to_struct hash
8
8
  end
9
9
 
10
- private
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.dot_notation_from(hash)
16
+ def self.hash_to_struct(hash)
13
17
  dotted = OpenStruct.new hash
14
18
  hash.each do |k, v|
15
- dotted[k] = dot_notation_from(v) if v.is_a? Hash
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.0
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-08 00:00:00.000000000 Z
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: Load YAML as configuration file
75
+ summary: YAML Config Loader
76
76
  test_files: []