configer 1.0.0 → 1.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 +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +33 -5
- data/VERSION +1 -1
- data/lib/configer.rb +6 -111
- data/lib/configer/data.rb +11 -0
- data/lib/configer/ext.rb +16 -0
- data/lib/configer/json.rb +52 -0
- data/lib/configer/yaml.rb +53 -0
- data/sample/load_meta_files.rb +4 -2
- data/sample/mount_opts.rb +12 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39df868488d3ebaaa6a5e6e9a8b23ab4f3a7e380
|
4
|
+
data.tar.gz: adf09670983135cc7ab5f019c919f286b2cda9d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8008aaa6e277c4e8d5e0159805e673bb7a47460d6a853203f68d0691e9319bc7188cad96bb62fa4efec6fa409e0bab47c1e2ab9d9bec04188ae36fd15ec369b0
|
7
|
+
data.tar.gz: ca383f93302dcddbd81d9ad437633dcda1bf15b778e554f1162143b70a91f736bb1b6f7168550091d986c92318c27971d97035a9b200c041dfeedd8343384a72
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -9,15 +9,43 @@ super easy to use configuration module for ruby apps
|
|
9
9
|
|
10
10
|
require_relative "../lib/configer.rb"
|
11
11
|
|
12
|
+
#> you can use root/r/folder key,
|
13
|
+
# for set home directory
|
14
|
+
#
|
15
|
+
#> you can point to an object if you want change the default __config__ obj
|
16
|
+
# keys: o/out/to
|
17
|
+
#
|
12
18
|
Configer.mount_yaml
|
13
19
|
Configer.mount_json
|
14
20
|
|
15
|
-
# this will
|
16
|
-
puts
|
21
|
+
# this will merge new objects by default to the __config__ object (or configer)
|
22
|
+
puts __config__ #> you can use configer alias as well
|
17
23
|
|
18
|
-
# for example we can call the
|
19
|
-
puts
|
20
|
-
puts
|
24
|
+
# for example we can call the dir.pwd folder's sample/meta/test.yml file parsed data as
|
25
|
+
puts __config__.sample.meta.test #> { hello: "world" }
|
26
|
+
puts __config__.sample.meta.test.hello #> "world"
|
27
|
+
|
28
|
+
```
|
29
|
+
|
30
|
+
example for the mount options:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
|
34
|
+
require "configer"
|
35
|
+
|
36
|
+
asdf= Configer::ConfigObject.new( {hello: "world"} )
|
37
|
+
|
38
|
+
Configer.mount_yaml out: asdf
|
39
|
+
Configer.mount_json out: asdf
|
40
|
+
|
41
|
+
puts __config__
|
42
|
+
#<Configer::ConfigObject>
|
43
|
+
|
44
|
+
puts asdf
|
45
|
+
#<Configer::ConfigObject hello="world"
|
46
|
+
# sample=#<Configer::ConfigObject meta=#<Configer::ConfigObject
|
47
|
+
# hello=#<Configer::ConfigObject hello="world">
|
48
|
+
# test=#<Configer::ConfigObject hello="world">>>>
|
21
49
|
|
22
50
|
|
23
51
|
```
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.1.0
|
data/lib/configer.rb
CHANGED
@@ -1,114 +1,9 @@
|
|
1
|
-
# require 'loader'
|
2
|
-
require 'hashie'
|
3
|
-
|
4
|
-
module Configer
|
5
|
-
|
6
|
-
ConfigObject= Class.new(::Hashie::Mash)
|
7
|
-
|
8
|
-
module Data
|
9
|
-
def self.config_hash
|
10
|
-
@@config ||= ConfigObject.new
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
module YamlFN
|
15
|
-
|
16
|
-
def mount_yaml_files opts= {}
|
17
|
-
raise(ArgumentError) unless opts.class <= Hash
|
18
|
-
require 'yaml'
|
19
|
-
|
20
|
-
opts[:root] ||= opts[:r] || opts[:root_folder] || Dir.pwd
|
21
|
-
|
22
|
-
#root_folder= ::Loader.caller_root
|
23
|
-
|
24
|
-
Dir.glob( File.join( File.absolute_path(opts[:root]), "**","*.{yaml,yml}" ) ).each do |file_path|
|
25
|
-
|
26
|
-
var= file_path.sub(opts[:root],"").split('.')
|
27
|
-
var.pop
|
28
|
-
var= var.join('.')
|
29
|
-
|
30
|
-
path_elements= var.split(File::Separator)
|
31
|
-
path_elements.delete('')
|
32
|
-
|
33
|
-
tmp_hsh= {}
|
34
|
-
current_obj= nil
|
35
|
-
|
36
|
-
path_elements.count.times { |index|
|
37
|
-
|
38
|
-
key_str= path_elements[index]
|
39
|
-
(current_obj ||= tmp_hsh)
|
40
|
-
current_obj[key_str]= {} #ConfigObject.new
|
41
|
-
current_obj= current_obj[key_str] unless index == (path_elements.count-1)
|
42
|
-
|
43
|
-
}
|
44
|
-
|
45
|
-
current_obj[ path_elements.last ]= YAML.safe_load File.read file_path
|
46
|
-
Data.config_hash.deep_merge!(tmp_hsh)
|
47
|
-
|
48
|
-
return nil
|
49
|
-
end
|
50
|
-
|
51
|
-
end
|
52
|
-
alias :mount_yaml :mount_yaml_files
|
53
|
-
alias :mount_yml :mount_yaml_files
|
54
|
-
|
55
|
-
end
|
56
|
-
|
57
|
-
module JSONFN
|
58
1
|
|
59
|
-
|
60
|
-
raise(ArgumentError) unless opts.class <= Hash
|
61
|
-
require 'json'
|
62
|
-
|
63
|
-
opts[:root] ||= opts[:r] || opts[:root_folder] || Dir.pwd
|
64
|
-
|
65
|
-
#root_folder= ::Loader.caller_root
|
66
|
-
|
67
|
-
Dir.glob( File.join( File.absolute_path(opts[:root]), "**","*.{json}" ) ).each do |file_path|
|
68
|
-
|
69
|
-
var= file_path.sub(opts[:root],"").split('.')
|
70
|
-
var.pop
|
71
|
-
var= var.join('.')
|
72
|
-
|
73
|
-
path_elements= var.split(File::Separator)
|
74
|
-
path_elements.delete('')
|
75
|
-
|
76
|
-
tmp_hsh= {}
|
77
|
-
current_obj= nil
|
78
|
-
|
79
|
-
path_elements.count.times { |index|
|
80
|
-
|
81
|
-
key_str= path_elements[index]
|
82
|
-
(current_obj ||= tmp_hsh)
|
83
|
-
current_obj[key_str]= {} #ConfigObject.new
|
84
|
-
current_obj= current_obj[key_str] unless index == (path_elements.count-1)
|
85
|
-
|
86
|
-
}
|
87
|
-
|
88
|
-
current_obj[ path_elements.last ]= JSON.parse File.read file_path
|
89
|
-
Data.config_hash.deep_merge!(tmp_hsh)
|
90
|
-
|
91
|
-
return nil
|
92
|
-
end
|
93
|
-
|
94
|
-
end
|
95
|
-
alias :mount_json :mount_json_files
|
96
|
-
|
97
|
-
end
|
98
|
-
|
99
|
-
extend YamlFN
|
100
|
-
extend JSONFN
|
101
|
-
|
102
|
-
module ObjectEXT
|
103
|
-
|
104
|
-
def configer
|
105
|
-
::Configer::Data.config_hash
|
106
|
-
end
|
107
|
-
|
108
|
-
alias :config :configer
|
109
|
-
|
110
|
-
end
|
2
|
+
require 'hashie'
|
111
3
|
|
112
|
-
|
4
|
+
require 'configer/data'
|
5
|
+
require 'configer/json'
|
6
|
+
require 'configer/yaml'
|
7
|
+
require 'configer/ext'
|
113
8
|
|
114
|
-
|
9
|
+
# require File.join(File.dirname(__FILE__),"configer","data")
|
data/lib/configer/ext.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
|
2
|
+
module Configer
|
3
|
+
|
4
|
+
module JSONFN
|
5
|
+
|
6
|
+
def mount_json_files opts= {}
|
7
|
+
raise(ArgumentError) unless opts.class <= Hash
|
8
|
+
require 'json'
|
9
|
+
|
10
|
+
opts[:root] ||= opts.delete(:r) || opts.delete(:folder) || Dir.pwd
|
11
|
+
opts[:out] ||= opts.delete(:o) || opts.delete(:to) || Configer::Data.config_hash
|
12
|
+
|
13
|
+
raise unless opts[:out].class <= Hash
|
14
|
+
unless opts[:out].class == Configer::ConfigObject
|
15
|
+
opts[:out]= Configer::ConfigObject.new( opts[:out] )
|
16
|
+
end
|
17
|
+
|
18
|
+
Dir.glob( File.join( File.absolute_path(opts[:root]), "**","*.{json}" ) ).each do |file_path|
|
19
|
+
|
20
|
+
var= file_path.sub(opts[:root],"").split('.')
|
21
|
+
var.pop
|
22
|
+
var= var.join('.')
|
23
|
+
|
24
|
+
path_elements= var.split(File::Separator)
|
25
|
+
path_elements.delete('')
|
26
|
+
|
27
|
+
tmp_hsh= {}
|
28
|
+
current_obj= nil
|
29
|
+
|
30
|
+
path_elements.count.times { |index|
|
31
|
+
|
32
|
+
key_str= path_elements[index]
|
33
|
+
(current_obj ||= tmp_hsh)
|
34
|
+
current_obj[key_str]= {} #ConfigObject.new
|
35
|
+
current_obj= current_obj[key_str] unless index == (path_elements.count-1)
|
36
|
+
|
37
|
+
}
|
38
|
+
|
39
|
+
current_obj[ path_elements.last ]= JSON.parse File.read file_path
|
40
|
+
opts[:out].deep_merge!(tmp_hsh)
|
41
|
+
|
42
|
+
return nil
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
alias :mount_json :mount_json_files
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
extend JSONFN
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
|
2
|
+
module Configer
|
3
|
+
|
4
|
+
module YamlFN
|
5
|
+
|
6
|
+
def mount_yaml_files opts= {}
|
7
|
+
raise(ArgumentError) unless opts.class <= Hash
|
8
|
+
require 'yaml'
|
9
|
+
|
10
|
+
opts[:root] ||= opts.delete(:r) || opts.delete(:folder) || Dir.pwd
|
11
|
+
opts[:out] ||= opts.delete(:o) || opts.delete(:to) || Configer::Data.config_hash
|
12
|
+
|
13
|
+
raise unless opts[:out].class <= Hash
|
14
|
+
unless opts[:out].class == Configer::ConfigObject
|
15
|
+
opts[:out]= Configer::ConfigObject.new( opts[:out] )
|
16
|
+
end
|
17
|
+
|
18
|
+
Dir.glob( File.join( File.absolute_path(opts[:root]), "**","*.{yaml,yml}" ) ).each do |file_path|
|
19
|
+
|
20
|
+
var= file_path.sub(opts[:root],"").split('.')
|
21
|
+
var.pop
|
22
|
+
var= var.join('.')
|
23
|
+
|
24
|
+
path_elements= var.split(File::Separator)
|
25
|
+
path_elements.delete('')
|
26
|
+
|
27
|
+
tmp_hsh= {}
|
28
|
+
current_obj= nil
|
29
|
+
|
30
|
+
path_elements.count.times { |index|
|
31
|
+
|
32
|
+
key_str= path_elements[index]
|
33
|
+
(current_obj ||= tmp_hsh)
|
34
|
+
current_obj[key_str]= {} #ConfigObject.new
|
35
|
+
current_obj= current_obj[key_str] unless index == (path_elements.count-1)
|
36
|
+
|
37
|
+
}
|
38
|
+
|
39
|
+
current_obj[ path_elements.last ]= YAML.safe_load File.read file_path
|
40
|
+
opts[:out].deep_merge!(tmp_hsh)
|
41
|
+
|
42
|
+
return nil
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
alias :mount_yaml :mount_yaml_files
|
47
|
+
alias :mount_yml :mount_yaml_files
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
extend YamlFN
|
52
|
+
|
53
|
+
end
|
data/sample/load_meta_files.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require "configer"
|
2
2
|
|
3
3
|
Configer.mount_yaml
|
4
4
|
Configer.mount_json
|
@@ -6,4 +6,6 @@ Configer.mount_json
|
|
6
6
|
configer #> config
|
7
7
|
|
8
8
|
# for example we can call the root/sample/meta/test.yml file parsed data as
|
9
|
-
puts configer.sample.meta.test #> { hello: world }
|
9
|
+
puts configer.sample.meta.test #> { hello: world }
|
10
|
+
|
11
|
+
config_obj= {}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "configer"
|
2
|
+
|
3
|
+
asdf= Configer::ConfigObject.new( {hello: "world"} )
|
4
|
+
|
5
|
+
Configer.mount_yaml out: asdf
|
6
|
+
Configer.mount_json out: asdf
|
7
|
+
|
8
|
+
puts __config__
|
9
|
+
#<Configer::ConfigObject>
|
10
|
+
|
11
|
+
# puts asdf
|
12
|
+
#<Configer::ConfigObject hello="world" sample=#<Configer::ConfigObject meta=#<Configer::ConfigObject hello=#<Configer::ConfigObject hello="world"> test=#<Configer::ConfigObject hello="world">>>>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: configer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Luzsi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashie
|
@@ -82,9 +82,14 @@ files:
|
|
82
82
|
- VERSION
|
83
83
|
- configer.gemspec
|
84
84
|
- lib/configer.rb
|
85
|
+
- lib/configer/data.rb
|
86
|
+
- lib/configer/ext.rb
|
87
|
+
- lib/configer/json.rb
|
88
|
+
- lib/configer/yaml.rb
|
85
89
|
- sample/load_meta_files.rb
|
86
90
|
- sample/meta/hello.json
|
87
91
|
- sample/meta/test.yml
|
92
|
+
- sample/mount_opts.rb
|
88
93
|
homepage:
|
89
94
|
licenses: []
|
90
95
|
metadata: {}
|