flex_config 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/flex_config/config_obj.rb +19 -0
- data/lib/flex_config.rb +68 -16
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39fdff2621755a3113b0102519cee359b767dbfd
|
4
|
+
data.tar.gz: e211bcafa3ffddaa84d030de886d281960926468
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 141b3610a9a3b2bda029416eb46ad488e14d27b1cd5552fc875724970e8d2ff4c25367355014afbce12f07e19cb47a3a3c837228c66a533bc88dc2a241bcadc8
|
7
|
+
data.tar.gz: 8ff7bc0c776479dde3fbd40198885fc38845633ee96e5696e8df17398c01b7f70eb471b90a439848dbef02fd29c9876767e63218bcf94ad406bf9faf03374a72
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class FlexConfig
|
2
|
+
|
3
|
+
class ConfigObj
|
4
|
+
|
5
|
+
def initialize (parent, key, contents)
|
6
|
+
@parent = parent
|
7
|
+
@key = key
|
8
|
+
@contents = contents
|
9
|
+
end
|
10
|
+
|
11
|
+
def method_missing (method, *args)
|
12
|
+
@contents.send(method, *args)
|
13
|
+
@parent.config[@key] = @contents
|
14
|
+
@parent.save_config
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
data/lib/flex_config.rb
CHANGED
@@ -1,31 +1,83 @@
|
|
1
|
+
require 'flex_config/config_obj'
|
2
|
+
require 'flex_mods'
|
1
3
|
require 'yaml'
|
2
4
|
|
3
5
|
class FlexConfig
|
4
|
-
def initialize (path, configs)
|
5
6
|
|
6
|
-
|
7
|
-
|
7
|
+
class << self
|
8
|
+
|
9
|
+
def get_config (path)
|
10
|
+
file_path = path + '/config.yml'
|
11
|
+
YAML::load(File.open(file_path, 'r'))
|
8
12
|
end
|
9
13
|
|
10
|
-
|
14
|
+
end
|
11
15
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
+
def initialize (path, configs)
|
17
|
+
|
18
|
+
file_path = check_path(path) + '/config.yml'
|
19
|
+
config = check_file(file_path)
|
20
|
+
|
21
|
+
case configs
|
22
|
+
when Hash
|
23
|
+
config.merge!(configs) unless configs == {}
|
24
|
+
when Array
|
25
|
+
new = {}
|
26
|
+
configs.each { |key| new[key] = {} }
|
27
|
+
config.merge!(new)
|
28
|
+
else
|
29
|
+
raise ArgumentError('Second argument must be a hash or array of keys')
|
16
30
|
end
|
17
31
|
|
18
|
-
config
|
32
|
+
@config = config
|
33
|
+
@file_path = file_path
|
19
34
|
|
20
|
-
|
21
|
-
|
22
|
-
output.close
|
35
|
+
save_config
|
36
|
+
end
|
23
37
|
|
38
|
+
def method_missing (method, *args)
|
39
|
+
@config.send(method, *args)
|
24
40
|
end
|
25
41
|
|
26
|
-
def
|
27
|
-
|
42
|
+
def [] (key)
|
43
|
+
state =
|
44
|
+
if @config[key].nil?
|
45
|
+
{}
|
46
|
+
else
|
47
|
+
@config[key].deep_copy
|
48
|
+
end
|
49
|
+
|
50
|
+
ConfigObj.new(self, key, state)
|
51
|
+
end
|
28
52
|
|
29
|
-
|
53
|
+
def to_h
|
54
|
+
@config
|
30
55
|
end
|
31
|
-
|
56
|
+
|
57
|
+
def check_path (path)
|
58
|
+
dir_path = path + '/config'
|
59
|
+
unless Dir.exist?(dir_path)
|
60
|
+
Dir.mkdir(dir_path)
|
61
|
+
end
|
62
|
+
dir_path
|
63
|
+
end
|
64
|
+
|
65
|
+
def check_file (path)
|
66
|
+
if File.exist?(path)
|
67
|
+
YAML::load(File.open(path, 'r'))
|
68
|
+
else
|
69
|
+
{}
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def save_config
|
74
|
+
output = File.open(@file_path, 'w')
|
75
|
+
output.puts @config.to_yaml
|
76
|
+
output.close
|
77
|
+
@config
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flex_config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eugene Lai
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: To do
|
14
14
|
email: ejt.lai@gmail.com
|
@@ -17,6 +17,7 @@ extensions: []
|
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
19
|
- lib/flex_config.rb
|
20
|
+
- lib/flex_config/config_obj.rb
|
20
21
|
homepage:
|
21
22
|
licenses: []
|
22
23
|
metadata: {}
|