configfile 0.1.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 +7 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/Rakefile +1 -0
- data/configfile.gemspec +31 -0
- data/lib/configfile.rb +76 -0
- data/lib/configfile/version.rb +3 -0
- metadata +91 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 77e9061481542e0a746cf04fafdc57745805bbf5
|
4
|
+
data.tar.gz: 6fda6e7c9c5daacb9bdf6cff73261b4236defe1e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0c027e84353e2af958c2bd4a770e73b80b173c5b6da09f267792d83408189ae9c510786a9aee954a7c893e655b872c0bbe2ed35b2638d900e04decd20d48c681
|
7
|
+
data.tar.gz: 9429c60f2f517b135af4cdc9d47bb3cddb386a8369f88632a7a80fe36279f8e6c2d47fbff30935990d9cab05161e5a9fd8122b816ecbd7575733dd190b67bcc7
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Jaci R Brunning
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/configfile.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'configfile/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "configfile"
|
8
|
+
spec.version = ConfigFile::VERSION
|
9
|
+
spec.authors = ["Jaci Brunning"]
|
10
|
+
spec.email = ["jaci.brunning@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{A simple reloadable config file system with defaults}
|
13
|
+
spec.homepage = "http://www.github.com/JacisNonsense/ConfigFile"
|
14
|
+
|
15
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
16
|
+
# delete this section to allow pushing this gem to any host.
|
17
|
+
# if spec.respond_to?(:metadata)
|
18
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
19
|
+
# else
|
20
|
+
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
21
|
+
# end
|
22
|
+
|
23
|
+
spec.files = Dir.glob("lib/**/*") + ['Rakefile', "configfile.gemspec", 'Gemfile', 'LICENSE']
|
24
|
+
spec.bindir = "bin"
|
25
|
+
spec.executables = []
|
26
|
+
spec.require_paths = ["lib"]
|
27
|
+
|
28
|
+
spec.add_development_dependency "bundler"
|
29
|
+
spec.add_development_dependency "rake"
|
30
|
+
spec.add_dependency "json"
|
31
|
+
end
|
data/lib/configfile.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
require "configfile/version"
|
2
|
+
require "yaml"
|
3
|
+
require "json"
|
4
|
+
|
5
|
+
class ConfigFile < Hash
|
6
|
+
|
7
|
+
def initialize filename, defaults={}, form=:yaml
|
8
|
+
@filename = filename
|
9
|
+
@defaults = defaults
|
10
|
+
@format = form
|
11
|
+
end
|
12
|
+
|
13
|
+
def defaults defaults
|
14
|
+
@defaults = defaults
|
15
|
+
end
|
16
|
+
|
17
|
+
def format form
|
18
|
+
@format = form
|
19
|
+
end
|
20
|
+
|
21
|
+
def parse str
|
22
|
+
if @format == :yaml
|
23
|
+
return YAML.load str
|
24
|
+
elsif @format == :json
|
25
|
+
return JSON.parse str
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def generate hash
|
30
|
+
if @format == :yaml
|
31
|
+
return hash.to_yaml
|
32
|
+
elsif @format == :json
|
33
|
+
return JSON.pretty_generate hash
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def save
|
38
|
+
File.write(@filename, generate(self))
|
39
|
+
end
|
40
|
+
|
41
|
+
def to_yaml
|
42
|
+
hnew = {}
|
43
|
+
self.each { |k,v| hnew[k] = v } # YAML doesn't like subclasses
|
44
|
+
hnew.to_yaml
|
45
|
+
end
|
46
|
+
|
47
|
+
def load
|
48
|
+
loaded = File.exist?(@filename) ? parse(File.read(@filename)) : {}
|
49
|
+
self.clear
|
50
|
+
self.merge! deep_merge(@defaults, loaded)
|
51
|
+
save
|
52
|
+
end
|
53
|
+
|
54
|
+
def []= name, value
|
55
|
+
super(name, value)
|
56
|
+
save
|
57
|
+
end
|
58
|
+
|
59
|
+
def deep_merge h1, h2
|
60
|
+
return h1 if h2 == false
|
61
|
+
newarray = h1.dup
|
62
|
+
h2.each do |key, val|
|
63
|
+
if val.is_a? Hash
|
64
|
+
if h1.include? key
|
65
|
+
newarray[key] = deep_merge h1[key], val
|
66
|
+
else
|
67
|
+
h1[key] = val
|
68
|
+
end
|
69
|
+
else
|
70
|
+
newarray[key] = val
|
71
|
+
end
|
72
|
+
end
|
73
|
+
newarray
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: configfile
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jaci Brunning
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '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: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- jaci.brunning@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- Gemfile
|
63
|
+
- LICENSE
|
64
|
+
- Rakefile
|
65
|
+
- configfile.gemspec
|
66
|
+
- lib/configfile.rb
|
67
|
+
- lib/configfile/version.rb
|
68
|
+
homepage: http://www.github.com/JacisNonsense/ConfigFile
|
69
|
+
licenses: []
|
70
|
+
metadata: {}
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 2.4.5
|
88
|
+
signing_key:
|
89
|
+
specification_version: 4
|
90
|
+
summary: A simple reloadable config file system with defaults
|
91
|
+
test_files: []
|