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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 967b15a461f7897e7dc1614c1dce0ddf61909692
4
- data.tar.gz: 9d3effb1c8c94a461bcf3f61cdb7ea7d611f8917
3
+ metadata.gz: 39df868488d3ebaaa6a5e6e9a8b23ab4f3a7e380
4
+ data.tar.gz: adf09670983135cc7ab5f019c919f286b2cda9d4
5
5
  SHA512:
6
- metadata.gz: 827822ae7a15db9b3076a967ce001065fe02bca837de77c8aecab7e8cda5a5ceea69522830a5cfa00451547736f64c8c325fa748b111c59cb2fe10ec4f5b99a5
7
- data.tar.gz: cc1d733812ed880af4f82fef03bca882c8b1bd77c60003e5c16433f339091989b5b5ea5a44388c86c2b553f28c43671a65b0f5f521c0992989fa37fc6dee92d5
6
+ metadata.gz: 8008aaa6e277c4e8d5e0159805e673bb7a47460d6a853203f68d0691e9319bc7188cad96bb62fa4efec6fa409e0bab47c1e2ab9d9bec04188ae36fd15ec369b0
7
+ data.tar.gz: ca383f93302dcddbd81d9ad437633dcda1bf15b778e554f1162143b70a91f736bb1b6f7168550091d986c92318c27971d97035a9b200c041dfeedd8343384a72
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- configer (1.0.0)
4
+ configer (1.1.0)
5
5
  hashie
6
6
  loader
7
7
 
@@ -9,7 +9,7 @@ GEM
9
9
  remote: http://rubygems.org/
10
10
  specs:
11
11
  hashie (2.1.1)
12
- loader (1.1.0)
12
+ loader (1.2.0)
13
13
  rake (10.3.1)
14
14
 
15
15
  PLATFORMS
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 return the config obj
16
- puts configer #> || use config alias
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 root/sample/meta/test.yml file parsed data as
19
- puts configer.sample.meta.test #> { hello: world }
20
- puts configer.sample.meta.test.hello #> { hello: world }
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.0.0
1
+ 1.1.0
@@ -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
- def mount_json_files opts= {}
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
- end
4
+ require 'configer/data'
5
+ require 'configer/json'
6
+ require 'configer/yaml'
7
+ require 'configer/ext'
113
8
 
114
- Object.__send__ :include, Configer::ObjectEXT
9
+ # require File.join(File.dirname(__FILE__),"configer","data")
@@ -0,0 +1,11 @@
1
+
2
+ module Configer
3
+
4
+ ConfigObject= Class.new(::Hashie::Mash)
5
+ module Data
6
+ def self.config_hash
7
+ @@config ||= ConfigObject.new
8
+ end
9
+ end
10
+
11
+ end
@@ -0,0 +1,16 @@
1
+
2
+ module Configer
3
+
4
+ module ObjectEXT
5
+
6
+ def configer
7
+ ::Configer::Data.config_hash
8
+ end
9
+
10
+ alias :__config__ :configer
11
+
12
+ end
13
+
14
+ end
15
+
16
+ Object.__send__ :include, Configer::ObjectEXT
@@ -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
@@ -1,4 +1,4 @@
1
- require_relative "../lib/configer.rb"
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.0.0
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-18 00:00:00.000000000 Z
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: {}