configer 0.0.1.pre.pre

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d1fda95b040388bca8a27b746c8b35e769e2339f
4
+ data.tar.gz: a518b9327105e9648555c0abff94d9852424749a
5
+ SHA512:
6
+ metadata.gz: a57c16d7848a10d3ef8e7562c733ef53f81a9e5131714baae001133a656f46b3df1e7a493a08ccf1e8525ba160fed7759c081260b77bbaf28ea1ad9427268703
7
+ data.tar.gz: 6adad0d2afb269dea6c0970f4f368ce147050348db1ec2abe41c6a132034ec2246c27052d21e9398b1a83b0ed003160d9fac132a8ba355bbd126a5a6a1670484
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ ./pkg/*
2
+ pkg
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :rubygems
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,21 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ configer (0.0.1.pre.pre)
5
+ hashie
6
+ loader
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ hashie (2.1.1)
12
+ loader (1.1.0)
13
+ rake (10.3.1)
14
+
15
+ PLATFORMS
16
+ ruby
17
+
18
+ DEPENDENCIES
19
+ bundler
20
+ configer!
21
+ rake
data/README.md ADDED
@@ -0,0 +1,23 @@
1
+ configer
2
+ ========
3
+
4
+ super easy to use configuration module for ruby apps
5
+
6
+ ### example
7
+
8
+ ```ruby
9
+
10
+ require_relative "../lib/configer.rb"
11
+
12
+ Configer.mount_yaml
13
+ Configer.mount_json
14
+
15
+ # this will return the config obj
16
+ puts configer #> || use config alias
17
+
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 }
21
+
22
+
23
+ ```
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require File.join"bundler","gem_tasks"
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1.pre.pre
data/configer.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+
3
+ Gem::Specification.new do |spec|
4
+
5
+ spec.name = "configer"
6
+ spec.version = File.open(File.join(File.dirname(__FILE__),"VERSION")).read.split("\n")[0].chomp.gsub(' ','')
7
+ spec.authors = ["Adam Luzsi"]
8
+ spec.email = ["adam.luzsi@ppt-consulting.net"]
9
+ spec.description = %q{ Easy to use config module for apps. Use file system based paths for yaml files, to create sub keys }
10
+ spec.summary = %q{ super easy to use config module for general use }
11
+
12
+ spec.files = `git ls-files`.split($/)
13
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
14
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
+ spec.require_paths = ["lib"]
16
+
17
+ spec.add_dependency "hashie"
18
+ spec.add_dependency "loader"
19
+
20
+ spec.add_development_dependency "bundler"
21
+ spec.add_development_dependency "rake"
22
+
23
+ end
data/lib/configer.rb ADDED
@@ -0,0 +1,111 @@
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= ConfigObject.new
34
+ current_obj= nil
35
+
36
+ path_elements.each { |key_str|
37
+
38
+ (current_obj ||= tmp_hsh)
39
+ current_obj[key_str]= ConfigObject.new
40
+ current_obj= current_obj[key_str]
41
+
42
+ }
43
+
44
+ current_obj= YAML.safe_load File.read file_path
45
+ Data.config_hash.deep_merge!(tmp_hsh)
46
+
47
+ end
48
+
49
+ end
50
+ alias :mount_yaml :mount_yaml_files
51
+ alias :mount_yml :mount_yaml_files
52
+
53
+ end
54
+
55
+ module JSONFN
56
+
57
+ def mount_json_files opts= {}
58
+ raise(ArgumentError) unless opts.class <= Hash
59
+ require 'json'
60
+
61
+ opts[:root] ||= opts[:r] || opts[:root_folder] || Dir.pwd
62
+
63
+ #root_folder= ::Loader.caller_root
64
+
65
+ Dir.glob( File.join( File.absolute_path(opts[:root]), "**","*.{json}" ) ).each do |file_path|
66
+
67
+ var= file_path.sub(opts[:root],"").split('.')
68
+ var.pop
69
+ var= var.join('.')
70
+
71
+ path_elements= var.split(File::Separator)
72
+ path_elements.delete('')
73
+
74
+ tmp_hsh= ConfigObject.new
75
+ current_obj= nil
76
+
77
+ path_elements.each { |key_str|
78
+
79
+ (current_obj ||= tmp_hsh)
80
+ current_obj[key_str]= ConfigObject.new
81
+ current_obj= current_obj[key_str]
82
+
83
+ }
84
+
85
+ current_obj= JSON.parse File.read file_path
86
+ puts tmp_hsh
87
+ Data.config_hash.deep_merge!(tmp_hsh)
88
+
89
+ end
90
+
91
+ end
92
+ alias :mount_json :mount_json_files
93
+
94
+ end
95
+
96
+ extend YamlFN
97
+ extend JSONFN
98
+
99
+ module ObjectEXT
100
+
101
+ def configer
102
+ ::Configer::Data.config_hash
103
+ end
104
+
105
+ alias :config :configer
106
+
107
+ end
108
+
109
+ end
110
+
111
+ Object.__send__ :include, Configer::ObjectEXT
@@ -0,0 +1,9 @@
1
+ require_relative "../lib/configer.rb"
2
+
3
+ Configer.mount_yaml
4
+ Configer.mount_json
5
+
6
+ configer #> config
7
+
8
+ # for example we can call the root/sample/meta/test.yml file parsed data as
9
+ # puts configer.sample.meta.test #> { hello: world }
@@ -0,0 +1 @@
1
+ {"hello":"world"}
@@ -0,0 +1 @@
1
+ hello: world
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: configer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.pre.pre
5
+ platform: ruby
6
+ authors:
7
+ - Adam Luzsi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: hashie
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
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: loader
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: " Easy to use config module for apps. Use file system based paths for
70
+ yaml files, to create sub keys "
71
+ email:
72
+ - adam.luzsi@ppt-consulting.net
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - Gemfile.lock
80
+ - README.md
81
+ - Rakefile
82
+ - VERSION
83
+ - configer.gemspec
84
+ - lib/configer.rb
85
+ - sample/load_meta_files.rb
86
+ - sample/meta/hello.json
87
+ - sample/meta/test.yml
88
+ homepage:
89
+ licenses: []
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">"
103
+ - !ruby/object:Gem::Version
104
+ version: 1.3.1
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.2.2
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: super easy to use config module for general use
111
+ test_files: []