configer 1.3.1 → 2.0.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: 289ebe062db31097bcb5eb65c166a5f263f21e59
4
- data.tar.gz: 1b3d4cb6ea1f7ae77af56eb29b4e5f76c54f9d0e
3
+ metadata.gz: 6424137c1e704d889527669ee3a3ebab41e17e4a
4
+ data.tar.gz: 8ab963a91032799c5bcedc81bdb227fbe9d6effd
5
5
  SHA512:
6
- metadata.gz: d92002648fcf9678f2eb6379cd6e5ea1c59fd69e58ab01377452ba1753aad7cb7a6719215985a10e8a92ca432d62490b6fd5c8fed078da9cce8423ecff59ee3c
7
- data.tar.gz: 6190430662b11cb980ce1cb7dee0dc6e3848e710d07116d8c8f1aa8c5b70f2343c721804cf500f91b317c950e68e31fcfe3f04cd027442e8abf96894baa5942e
6
+ metadata.gz: 50f6e1ca2b408ff17e523365fa4836e33c5bb93d60814c925d1190b2210c5dd2fd9866862b2b06e1c80c5e08e8644d98779cc697448d47429676f2f9511b95cd
7
+ data.tar.gz: 4716dc327b3d12a2306457be19c63555a76a4f64abb404a0bf2bdd5ccf87beccdd50c4d10ac8e4589c137e17ac4fc929f178e49f0fef8248c81adf709ac11a48
data/README.md CHANGED
@@ -1,75 +1,71 @@
1
1
  configer
2
2
  ========
3
- super easy to use configuration module for ruby apps
3
+
4
+ super easy to use configuration module for ruby apps.
4
5
 
5
6
  ### install
6
7
 
7
8
  $ gem install configer
8
9
 
9
- ### example
10
+ ### Description
11
+
12
+ Configer is a support gem, to give the developer ability,
13
+ creating meta config files, that should be loaded into the application.
14
+
15
+ Configer follow the traditional ways in this field, and use the following Filesystem logic:
16
+
17
+ mounting configuration files as they are
18
+
19
+ ./project_dir/config/*
20
+
21
+ mounting environment configuration file as they are based on the current envernioment stage (development,test,production,staging)
22
+ * envirnomens folder name can be also envs/env/environment
23
+
24
+ ./project_dir/config/environments/*
25
+
26
+ mounting configuration files from lib/meta folder.
27
+ * Each config file name will be a "key" in the main config object
28
+ * same goes with the folders in the meta file
29
+ * the serialized object will be the value
30
+
31
+ ./project_dir/lib/meta/**/*
32
+
33
+ mounting configuration files from lib/module_name/meta folder.
34
+ * Each config file name will be a "key" in the config object that is located under the module_name key in the main config object
35
+ * same goes with the folders in the meta file
36
+ * the serialized object will be the value
37
+
38
+ ./project_dir/lib/module_name/meta/**/*
39
+
40
+
41
+ The meta folder name can be aliased with META
42
+
43
+ #### example
44
+
45
+ in the /test/sample_root you can see an example
10
46
 
11
47
  #### Lazy Config object
12
48
 
13
- The configers default behavior is , when you put a yaml or a json file into the following directories
14
- * app_root/lib/meta/**/*
15
- * app_root/lib/meta/*
16
- * app_root/lib/custom_libary_name/meta/*
17
- * app_root/config/*
18
- * app_root/config/environments/*
19
-
20
- The meta tag can be aliased with META
21
-
22
- The logic is the following:
23
- * in the lib/meta/*
24
- * will be merged into the __config__ hash object under the key of the file name
25
- * in the lib/meta/folder/*
26
- * will be merged into the __config__ object with the folder as main key and under that file name as key for the content
27
- * in the lib/folder/meta/*
28
- * will be merged into the __config__ object with the folder as main key, and the file names as sub keys followed by the content
29
- * in the config/* && config/environments/*
30
- * will be merged into the __config__ object as is. Deep merge will used so already existing keys will only be override partially
31
- * the following is the order if yaml/json files names as enviornments
32
- * default
33
- * development
34
- * test
35
- * production
36
-
37
- I personally say, put everything into the lib/gem_name/meta/* so you can have auto separated configs for each gem/module
38
49
  The __config__ object will not be generated util it's being called.
39
50
 
40
- #### Loading up Yaml and Json files from the application directory
51
+ #### Instance
41
52
 
42
- You can mount JSON and yaml files with manually.
43
- This will make key paths based on FileSystem logic
53
+ config object can be made into simple instance, based on argument passed folder path
44
54
 
45
- ```ruby
55
+ #### ERB support
46
56
 
47
- require "configer"
57
+ config files support ERB parsing if the file contain .erb extension in the name
48
58
 
49
- #> optons:
50
- #
51
- # root/r/folder/dir/directory
52
- # - set the folder where the mount will begin
53
- #
54
- # to/out/o
55
- # - point to a hashlike object where you want the config objects to be merged
56
- #
57
- Configer.mount_yaml #> return Configer::Object that contain parsed yaml
58
- Configer.mount_json #> return Configer::Object that contain parsed json
59
+ #### Supported Serializations
59
60
 
60
- ```
61
+ the current supported parsing logic are Yaml and JSON, that could be mixed with ERB
61
62
 
62
- example for the mount options:
63
-
64
- ```ruby
63
+ ### example
65
64
 
66
- require "configer"
65
+ __config__.grape.defaults #> return the config object that is located under {"grape"=>{"defaults"=>{...}}}
67
66
 
68
- asdf = {hello: "world"}
67
+ ### after words
69
68
 
70
- Configer.mount_yaml out: asdf
71
- Configer.mount_json out: asdf
69
+ I personally say, put everything into the lib/gem_name/meta/**/* so you can have auto separated configs for each gem/module
72
70
 
73
- puts asdf
74
71
 
75
- ```
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.1
1
+ 2.0.0
@@ -2,19 +2,22 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
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 = ["adamluzsi@gmail.com"]
9
- spec.description = %q{ Easy to use config module. Based on FileSystem logic, check gitHub for more info }
10
- spec.summary = %q{ super easy to use config module for general use }
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 = ['adamluzsi@gmail.com']
9
+ spec.description = %q{ Easy to use config module. Based on generally accepted FileSystem positions, check gitHub for more info }
10
+ spec.summary = %q{ Clean and easy to use config module for general use }
11
11
 
12
12
  spec.files = `git ls-files`.split($/)
13
13
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
14
14
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
- spec.require_paths = ["lib"]
15
+ spec.require_paths = ['lib']
16
+ spec.homepage = "https://github.com/adamluzsi/#{__dir__.split(File::Separator).last.split('.').first}"
16
17
 
17
- spec.add_development_dependency "bundler"
18
- spec.add_development_dependency "rake"
18
+ spec.required_ruby_version = '>= 2.0.0'
19
+
20
+ spec.add_development_dependency 'bundler'
21
+ spec.add_development_dependency 'rake'
19
22
 
20
23
  end
@@ -1,8 +1,9 @@
1
- require 'configer/extension'
2
- require 'configer/object'
1
+ require 'configer/ext'
2
+ require 'configer/logic'
3
3
  require 'configer/support'
4
-
5
- require 'configer/json'
6
- require 'configer/yaml'
7
-
4
+ require 'configer/object'
5
+ require 'configer/cache'
6
+ require 'configer/mount'
8
7
  require 'configer/dsl'
8
+
9
+ require 'configer/instance'
@@ -0,0 +1,20 @@
1
+ module Configer
2
+ module Cache
3
+ class << self
4
+
5
+ def object
6
+
7
+ @dir ||= Configer.pwd
8
+ if @dir == Configer.pwd
9
+ return @cache ||= Object.parse(Configer.mount_all)
10
+ else
11
+ @dir = Configer.pwd
12
+ return @cache = Object.parse(Configer.mount_all)
13
+ end
14
+
15
+ end
16
+
17
+
18
+ end
19
+ end
20
+ end
@@ -1,10 +1,9 @@
1
-
2
1
  module Configer
3
2
 
4
3
  module ObjectEXT
5
4
 
6
5
  def __config__
7
- ::Configer::Data.config_hash
6
+ ::Configer::Cache.object
8
7
  end;alias __CONFIG__ __config__
9
8
 
10
9
  end
@@ -3,22 +3,16 @@ module Configer
3
3
  module HashExtension
4
4
 
5
5
  def deep_merge(other_hash)
6
-
7
- var = self.dup
8
- var.__send__ :extend, HashExtension unless var.respond_to?(:deep_merge!)
9
-
10
- return var.__send__ :deep_merge!, other_hash
11
-
6
+ return self.dup.deep_merge!(other_hash)
12
7
  end
13
8
 
14
9
  def deep_merge!(other_hash)
15
10
 
16
11
  other_hash.each_pair do |k,v|
17
-
18
12
  self[k] = if self[k].class <= ::Hash && v.class <= ::Hash
19
13
 
20
14
  [self[k],v].each do |obj|
21
- obj.__send__ :extend, HashExtension unless obj.respond_to?(:deep_merge!)
15
+ obj.__send__ :extend, HashExtension unless obj.respond_to?(:deep_merge)
22
16
  end
23
17
 
24
18
  self[k].deep_merge(v)
@@ -36,5 +30,4 @@ module Configer
36
30
  end
37
31
 
38
32
 
39
-
40
33
  end
@@ -0,0 +1,14 @@
1
+ module Configer
2
+
3
+ def self.new(pwd)
4
+
5
+ raise(
6
+ ArgumentError,
7
+ 'Configer::Instance can only be made with valid folder path!'
8
+ ) unless File.exist?(pwd)
9
+
10
+ return Object.parse(Configer.mount_all(pwd))
11
+
12
+ end
13
+
14
+ end
@@ -0,0 +1,165 @@
1
+ module Configer
2
+
3
+ module Helpers
4
+
5
+ def supported_formats
6
+ @formats ||= %W[ erb json yaml yml ]
7
+ end
8
+
9
+ def parser(file_path)
10
+
11
+ file_string = if file_path.downcase =~ /\.erb\.?/
12
+ require 'erb'
13
+ ERB.new(File.read(file_path)).result
14
+ else
15
+ File.read(file_path)
16
+ end
17
+
18
+ object = if file_path =~ /\.ya?ml(\.erb)?$/
19
+ require 'yaml'
20
+ #> back compatibility for old yaml parse logic
21
+ if YAML.respond_to?(:save_load)
22
+ YAML.safe_load(file_string)
23
+ else
24
+ YAML.load(file_string)
25
+ end
26
+
27
+ elsif file_path =~ /\.json(\.erb)?$/
28
+ require 'json'
29
+ JSON.parse(file_string)
30
+
31
+ else
32
+ file_string
33
+
34
+ end
35
+
36
+
37
+ return Object.parse(object)
38
+
39
+ rescue;nil
40
+ end
41
+
42
+ def name_parser(name_str)
43
+ name_str.gsub(/(\.json|\.yaml|\.yml|\.erb)/,'')
44
+ end
45
+
46
+ #> opts:
47
+ #
48
+ # category:
49
+ # namespace where the gathered meta file datas will be merged
50
+ #
51
+ # split_at:
52
+ # string or regexp where the meta folder located
53
+ def mount_process( *paths,break_if: -> e { e.size > 2 }, namespace_less: false )
54
+ return paths.reduce(Object.new) do |m,file_path|
55
+
56
+ if namespace_less
57
+ #> if some non matching type wanted to be merged
58
+ m.deep_merge!(parser(file_path)) rescue nil
59
+ else
60
+
61
+ #> keys will be downcase anyways
62
+ elements = []
63
+ file_path.split(File::Separator).reverse.each do |element|
64
+ next if element =~ /^(META|meta)$/
65
+ break if element =~ /^(config|libs?)$/
66
+
67
+ elements.unshift element
68
+ break if break_if.call(elements)
69
+
70
+ end
71
+
72
+ key_cains = []
73
+ m.deep_merge!(
74
+ elements.reduce(Object.new) do |mem,element|
75
+
76
+ target_obj = mem
77
+ key_cains.each{|k| target_obj = target_obj[k] }
78
+ key_cains.push(element)
79
+
80
+ if elements[-1] == element
81
+ target_obj[name_parser(element)] = parser(file_path)
82
+
83
+ else
84
+ target_obj[name_parser(element)] ||= Object.new
85
+
86
+ end;mem
87
+
88
+ end
89
+ )
90
+
91
+ end;m
92
+
93
+ end
94
+ end
95
+
96
+ def mount_lib_meta(get_pwd=Configer.pwd)
97
+
98
+ mount_process(
99
+ *Dir.glob(
100
+ File.join(
101
+ get_pwd,
102
+ '{lib,libs}',
103
+ '{meta,META}',
104
+ '**',
105
+ "*.{#{supported_formats.join(',')}}"
106
+ )
107
+ )
108
+ )
109
+
110
+ end
111
+
112
+ def mount_lib_module_meta(get_pwd=Configer.pwd)
113
+
114
+ mount_process(
115
+ *Dir.glob(
116
+ File.join(
117
+ get_pwd,
118
+ '{lib,libs}',
119
+ '*',
120
+ '{meta,META}',
121
+ '**',
122
+ "*.{#{supported_formats.join(',')}}"
123
+ )
124
+ )
125
+ )
126
+ end
127
+
128
+ def mount_config(get_pwd=Configer.pwd)
129
+
130
+ mount_process(
131
+ *Dir.glob(
132
+ File.join(
133
+ get_pwd,
134
+ 'config',
135
+ "*.{#{supported_formats.join(',')}}"
136
+ )
137
+ ),
138
+ break_if: -> e { e.size == 1 },
139
+ namespace_less: true
140
+ )
141
+
142
+ end
143
+
144
+ def mount_config_environments(get_pwd=Configer.pwd)
145
+
146
+ mount_process(
147
+ *Dir.glob(
148
+ File.join(
149
+ get_pwd,
150
+ 'config',
151
+ '{environments,environment,env,envs}',
152
+ "#{Configer.env}.{#{supported_formats.join(',')}}"
153
+ )
154
+ ),
155
+ break_if: -> e { e.size >= 1 },
156
+ namespace_less: true
157
+ )
158
+
159
+ end
160
+
161
+ end
162
+
163
+ extend Helpers
164
+
165
+ end
@@ -0,0 +1,18 @@
1
+ module Configer
2
+ class << self
3
+
4
+ def mount_all(get_pwd=Configer.pwd)
5
+ return [
6
+
7
+ mount_lib_meta(get_pwd),
8
+ mount_lib_module_meta(get_pwd),
9
+
10
+ mount_config(get_pwd),
11
+ mount_config_environments(get_pwd)
12
+
13
+ ].reduce(Object.new){|m,o| m.deep_merge!(o) rescue nil ;m}
14
+ end
15
+
16
+
17
+ end
18
+ end
@@ -2,98 +2,62 @@ module Configer
2
2
 
3
3
  class Object < Hash
4
4
 
5
+ include HashExtension
5
6
  self.instance_methods.each do |sym|
6
- self.__send__ :protected, sym
7
+ protected sym
7
8
  end
8
9
 
9
- def method_missing( method_name, *args )
10
+ public :__send__,:public_send,:[],:[]=
11
+ def method_missing( method_name, *args, &block )
10
12
 
11
- if method_name[-1] == '='
13
+ obj_methods = self.__send__(:methods)
14
+ if method_name[-1] == '=' && !obj_methods.include?(method_name)
12
15
  self[method_name[0..-2]]= *args
13
16
  return self[method_name[0..-2]]
14
17
 
15
- else
16
- #> respond to method only if no value present
17
- if self[method_name.to_s].nil? && self.respond_to?(method_name)
18
- return self.__send__(method_name)
18
+ elsif self[method_name.to_s].nil? && obj_methods.include?(method_name)
19
19
 
20
+ if block_given?
21
+ return self.__send__(method_name,*args,&block)
20
22
  else
21
- return self[method_name.to_s]
22
-
23
+ return self.__send__(method_name,*args)
23
24
  end
24
25
 
26
+ else
27
+ return self[method_name.to_s]
28
+
25
29
  end
26
30
 
27
31
  end
28
32
 
29
- public :__send__,:public_send,:respond_to?
30
-
31
- #> some allowed Hash methods
32
- public :to_s,:inspect,:delete,:delete_if,
33
- :merge!,:merge,:keys,:values,:freeze
34
-
35
- #> allowed Enumerable methods
36
- public :each,:each_pair,:map,:reduce,:group_by,
37
- :select,:to_a,:grep,:count,:size
38
-
39
- #> allowed object methods
40
- public :class,:dup
41
-
42
- #> allowed boolean methods
43
- public :==,:===,:include?
44
-
45
33
  public
46
34
 
47
- def [] key
35
+ def [](key)
48
36
  key = key.to_s if key.class <= Symbol
49
37
  super || super(key.to_sym)
50
38
  end
51
39
 
52
- def []= key,value
40
+ def []=(key,value)
53
41
  key = key.to_s if key.class <= Symbol
54
42
  super
55
43
  end
56
44
 
57
45
  #> parse object
58
46
  def self.parse(obj)
47
+ case obj
59
48
 
60
- return case
61
-
62
- when obj.class <= Hash
63
- obj.reduce(self.new){|m,h| m.merge!( (h[0].class <= Symbol ? h[0].to_s : h[0] ) => self.parse(h[1]) ) ;m}
49
+ when Hash
50
+ obj.reduce(self.new){|m,h|
51
+ m.deep_merge!( (h[0].class <= Symbol ? h[0].to_s : h[0] ) => self.parse(h[1]) ) ;m}
64
52
 
65
- when obj.class <= Array
66
- obj.map{|o| self.parse(o) }
53
+ when Array
54
+ obj.map{|o| self.parse(o) }
67
55
 
68
- else
69
- obj
70
-
71
- end
72
-
73
- end
74
-
75
- end
76
-
77
- module Data
78
-
79
- #> i dont know why , but if i catch this ,
80
- # than somethimes some object happens to not get parsed
81
- def self.config_hash
82
- return Object.parse(Support.mount_config_and_lib_meta)
83
- end
84
-
85
- end
86
-
87
- class << self
88
-
89
- def new *args
90
- self::Object.new(*args)
91
- end
56
+ else
57
+ obj
92
58
 
93
- alias :init :new
59
+ end
94
60
 
95
- def parse(obj)
96
- self::Object.parse(obj)
97
61
  end
98
62
 
99
63
  end
@@ -1,126 +1,54 @@
1
1
  module Configer
2
2
 
3
- def self.pwd
3
+ class << self
4
4
 
5
- if defined?(Rails) && !(Rails.root.nil?)
6
- return Rails.root.to_s
7
- else
8
- return Dir.pwd.to_s
9
- end
10
-
11
- end
12
-
13
- module Support
14
-
15
- #> return mounted config objects
16
- def self.mount_config_and_lib_meta
17
-
18
- return_hash = {}
19
- return_hash.__send__ :extend, HashExtension
20
-
21
- config_yaml_paths= []
22
- config_yaml_paths.instance_eval do
23
- def push_path(*paths)
24
- paths.each do |path|
25
- case true
26
-
27
- when path.downcase.include?('default')
28
- self.insert 0, path
29
-
30
- when path.downcase.include?('development')
31
- self.insert 1, path
32
-
33
- when path.downcase.include?('test')
34
- self.insert 2, path
35
-
36
- when path.downcase.include?('production')
37
- self.insert 3, path
38
-
39
- else
40
- self.push path
5
+ def pwd
41
6
 
42
- end
43
- end
44
- end;alias push_paths push_path
7
+ if defined?(Rails) && !Rails.root.nil?
8
+ return Rails.root.to_s
9
+ else
10
+ return Dir.pwd.to_s
45
11
  end
46
12
 
47
- #> load lib meta folders files
48
- if File.exist?(File.join(Configer.pwd,'lib'))
49
- config_yaml_paths.push_paths *Dir.glob(File.join(Configer.pwd,'lib','**','{meta,META}','*.{yaml,yml,json}'))
50
- config_yaml_paths.push_paths *Dir.glob(File.join(Configer.pwd,'lib','{meta,META}','**','*.{yaml,yml,json}'))
51
- config_yaml_paths.compact!
52
- end
53
-
54
- #> load config folder
55
- if File.exist?(File.join(Configer.pwd,'config'))
56
-
57
- config_yaml_paths.push_paths *Dir.glob(File.join(Configer.pwd,'config','*.{yaml,yml,json}'))
58
- if File.exist?(File.join(Configer.pwd,'config','environments'))
59
- config_yaml_paths.push_paths *Dir.glob(File.join(Configer.pwd,'config','environments','*.{yaml,yml,json}'))
60
- end
61
- config_yaml_paths.compact!
62
-
63
- end
64
-
65
- config_yaml_paths.each do |path|
66
-
67
- path_parts = path.split(File::Separator)
13
+ end
68
14
 
69
- extension = path_parts.last.split('.')[-1]
70
15
 
71
- category_key = case
16
+ def env
72
17
 
73
- #> lib/meta/*
74
- when path_parts[-2].downcase == 'meta' && path_parts[-3] == 'lib'
75
- nil
18
+ if defined?(Rails) && !Rails.env.nil?
19
+ return Rails.env.to_s
76
20
 
77
- #> lib/meta/**/*
78
- when path_parts[-3].downcase == 'meta' && path_parts[-4] == 'lib'
79
- path_parts[-2]
21
+ elsif !ENV['RAILS_ENV'].nil?
22
+ return ENV['RAILS_ENV'].to_s
80
23
 
81
- #> lib/**/meta/*
82
- when path_parts[-2].downcase == 'meta' && path_parts[-3] != 'lib' && path_parts[-4] == 'lib'
83
- path_parts[-3]
24
+ elsif !ENV['RACK_ENV'].nil?
25
+ return ENV['RACK_ENV'].to_s
84
26
 
85
- else
86
- nil
27
+ elsif !ENV['STAGE'].nil?
28
+ case ENV['STAGE'].to_s.downcase
87
29
 
88
- end
30
+ when /^dev/
31
+ return 'development'
89
32
 
90
- object = if %W[ yaml yml ].include?(extension)
91
- require 'yaml'
33
+ when /^test/
34
+ return 'test'
92
35
 
93
- if YAML.respond_to?(:save_load)
94
- YAML.safe_load(File.read(path))
95
- else
96
- YAML.load(File.read(path))
97
- end
36
+ when /^prod/,/^stag/
37
+ return 'production'
98
38
 
99
- elsif extension == 'json'
100
- require 'json'
101
- JSON.parse(File.read(path))
102
- else
103
- {}
104
- end
39
+ else
40
+ return ENV['STAGE']
105
41
 
106
- if path.downcase.include?('meta')
107
- object = {
108
- ( path_parts.last.split('.')[-2] || path ) => object
109
- }
110
42
  end
111
43
 
112
- if category_key.nil?
113
- return_hash.deep_merge!(object)
114
- else
115
- return_hash.deep_merge!(category_key => object)
116
- end
44
+ else
45
+ return ENV.find{|k,v|
46
+ %W[ production development ].include?(v.to_s)
47
+ } || 'development'
117
48
 
118
49
  end
119
50
 
120
- return return_hash
121
-
122
51
  end
123
52
 
124
-
125
53
  end
126
54
  end
@@ -0,0 +1,4 @@
1
+ default_key: default_value
2
+ module_name:
3
+ module_name_key:
4
+ hello: <%= Random.rand %>
@@ -0,0 +1 @@
1
+ development_key: 'yep'
@@ -0,0 +1 @@
1
+ sub_key: <%= Random.rand %>
@@ -0,0 +1,2 @@
1
+ module_name_key:
2
+ module_name_value_hash_key: module_name_value_hash_value
@@ -0,0 +1 @@
1
+ config_key: config_value
@@ -0,0 +1,2 @@
1
+ --- hello world!
2
+ ...
@@ -0,0 +1,3 @@
1
+ require_relative 'test_helper'
2
+ require_relative 'test_config_object'
3
+ require_relative 'test_instance'
@@ -0,0 +1,47 @@
1
+ require_relative 'test_helper'
2
+
3
+ #> TEST dir root for fake the project root
4
+ Dir.chdir(File.realpath(File.join(__dir__,'sample_root')))
5
+
6
+ describe 'configer' do
7
+
8
+ it 'should be able to fetch values with different access' do
9
+
10
+ var = __config__ #> put into variable for check cache
11
+
12
+ #> test caching
13
+ __config__.__send__(:object_id).must_be :==,var.__send__(:object_id)
14
+
15
+ #> test accessing logic
16
+ __config__.default_key.must_be :==,__config__['default_key']
17
+ __config__.default_key.must_be :==,__config__[:default_key]
18
+ __config__.default_key.must_be :==,__config__.public_send(:default_key)
19
+
20
+ end
21
+
22
+ it 'should mount all the config files up!' do
23
+
24
+ #> config && erb
25
+ __config__.default_key.must_be :==,'default_value'
26
+ __config__.module_name.module_name_key.hello.must_be_instance_of Float
27
+ __config__.sub_key.must_be_instance_of Float
28
+
29
+ #> config/env
30
+ if Configer.env == 'development'
31
+ __config__.development_key.must_be :==, 'yep'
32
+ else
33
+ __config__.development_key.must_be :==, nil
34
+ end
35
+
36
+ #> lib/meta
37
+ __config__.module_name.module_name_key.module_name_value_hash_key.must_be :==, 'module_name_value_hash_value'
38
+
39
+ #> lib/module_name/meta
40
+ __config__.sample.config.config_key.must_be :==,'config_value'
41
+
42
+ #> string value in config object /as yaml format/
43
+ __config__.sample.string.must_be :==,'hello world!'
44
+
45
+ end
46
+
47
+ end
@@ -0,0 +1,4 @@
1
+ $TEST = true
2
+
3
+ require 'configer'
4
+ require 'minitest/autorun'
@@ -0,0 +1,48 @@
1
+ require_relative 'test_helper'
2
+
3
+ describe 'configer' do
4
+
5
+ before do
6
+ @config = Configer.new(File.join(File.realpath(__dir__),'sample_root'))
7
+ end
8
+
9
+ it 'should be able to fetch values with different access' do
10
+
11
+ var = @config #> put into variable for check cache
12
+
13
+ #> test caching
14
+ @config.__send__(:object_id).must_be :==,var.__send__(:object_id)
15
+
16
+ #> test accessing logic
17
+ @config.default_key.must_be :==,@config['default_key']
18
+ @config.default_key.must_be :==,@config[:default_key]
19
+ @config.default_key.must_be :==,@config.public_send(:default_key)
20
+
21
+ end
22
+
23
+ it 'should mount all the config files up!' do
24
+
25
+ #> config && erb
26
+ @config.default_key.must_be :==,'default_value'
27
+ @config.module_name.module_name_key.hello.must_be_instance_of Float
28
+ @config.sub_key.must_be_instance_of Float
29
+
30
+ #> config/env
31
+ if Configer.env == 'development'
32
+ @config.development_key.must_be :==, 'yep'
33
+ else
34
+ @config.development_key.must_be :==, nil
35
+ end
36
+
37
+ #> lib/meta
38
+ @config.module_name.module_name_key.module_name_value_hash_key.must_be :==, 'module_name_value_hash_value'
39
+
40
+ #> lib/module_name/meta
41
+ @config.sample.config.config_key.must_be :==,'config_value'
42
+
43
+ #> string value in config object /as yaml format/
44
+ @config.sample.string.must_be :==,'hello world!'
45
+
46
+ end
47
+
48
+ end
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.3.1
4
+ version: 2.0.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-10-01 00:00:00.000000000 Z
11
+ date: 2014-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,8 +38,8 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- description: " Easy to use config module. Based on FileSystem logic, check gitHub
42
- for more info "
41
+ description: " Easy to use config module. Based on generally accepted FileSystem positions,
42
+ check gitHub for more info "
43
43
  email:
44
44
  - adamluzsi@gmail.com
45
45
  executables: []
@@ -51,25 +51,27 @@ files:
51
51
  - README.md
52
52
  - Rakefile
53
53
  - VERSION
54
- - config/sample.yml
55
54
  - configer.gemspec
56
- - example/lazy_load.rb
57
- - example/sample.rb
58
55
  - lib/configer.rb
56
+ - lib/configer/cache.rb
59
57
  - lib/configer/dsl.rb
60
- - lib/configer/extension.rb
61
- - lib/configer/json.rb
62
- - lib/configer/meta/config.yml
58
+ - lib/configer/ext.rb
59
+ - lib/configer/instance.rb
60
+ - lib/configer/logic.rb
61
+ - lib/configer/mount.rb
63
62
  - lib/configer/object.rb
64
63
  - lib/configer/support.rb
65
- - lib/configer/yaml.rb
66
- - pmip/pmip.rb
67
- - sample/load_meta_files.rb
68
- - sample/meta/hello.json
69
- - sample/meta/test.yml
70
- - sample/mount_opts.rb
71
- - sandbox/sup.rb
72
- homepage:
64
+ - test/sample_root/config/defaults.erb.yml
65
+ - test/sample_root/config/environments/development.yml
66
+ - test/sample_root/config/erb_test.yml.erb
67
+ - test/sample_root/lib/meta/module_name.yml
68
+ - test/sample_root/lib/sample/meta/config.yml
69
+ - test/sample_root/lib/sample/meta/string.yml
70
+ - test/test_all.rb
71
+ - test/test_config_object.rb
72
+ - test/test_helper.rb
73
+ - test/test_instance.rb
74
+ homepage: https://github.com/adamluzsi/configer
73
75
  licenses: []
74
76
  metadata: {}
75
77
  post_install_message:
@@ -80,7 +82,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
80
82
  requirements:
81
83
  - - ">="
82
84
  - !ruby/object:Gem::Version
83
- version: '0'
85
+ version: 2.0.0
84
86
  required_rubygems_version: !ruby/object:Gem::Requirement
85
87
  requirements:
86
88
  - - ">="
@@ -91,6 +93,16 @@ rubyforge_project:
91
93
  rubygems_version: 2.2.2
92
94
  signing_key:
93
95
  specification_version: 4
94
- summary: super easy to use config module for general use
95
- test_files: []
96
+ summary: Clean and easy to use config module for general use
97
+ test_files:
98
+ - test/sample_root/config/defaults.erb.yml
99
+ - test/sample_root/config/environments/development.yml
100
+ - test/sample_root/config/erb_test.yml.erb
101
+ - test/sample_root/lib/meta/module_name.yml
102
+ - test/sample_root/lib/sample/meta/config.yml
103
+ - test/sample_root/lib/sample/meta/string.yml
104
+ - test/test_all.rb
105
+ - test/test_config_object.rb
106
+ - test/test_helper.rb
107
+ - test/test_instance.rb
96
108
  has_rdoc:
@@ -1,5 +0,0 @@
1
- hello: "world"
2
- test: "no"
3
- test:
4
- this:
5
- value: "hello world!"
@@ -1,7 +0,0 @@
1
- require "configer"
2
-
3
- puts __CONFIG__.public_send(:test)
4
- puts __CONFIG__.test.this.__send__ :class
5
-
6
- puts Configer.parse(hello: 'world')
7
- puts __CONFIG__.configer.config.class
@@ -1,8 +0,0 @@
1
- require "configer"
2
-
3
- asdf = {hello: "world"}
4
-
5
- Configer.mount_yaml out: asdf
6
- Configer.mount_json out: asdf
7
-
8
- puts asdf
@@ -1,54 +0,0 @@
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
- [:r,:folder,:dir,:directory].each do |sym|
11
- opts[:root] ||= opts.delete(sym)
12
- end
13
- opts[:root] ||= Configer.pwd
14
-
15
- opts[:out] ||= opts.delete(:o) || opts.delete(:to) || Configer::Object
16
- raise(ArgumentError,"out/to must point to hashlike object") unless opts[:out].class <= ::Hash
17
- opts[:out].__send__ :extend, HashExtension unless opts[:out].respond_to?(:deep_merge!)
18
-
19
- Dir.glob( File.join( File.absolute_path(opts[:root]), "**","*.{json}" ) ).each do |file_path|
20
-
21
- var= file_path.sub(opts[:root],"").split('.')
22
- var.pop
23
- var= var.join('.')
24
-
25
- path_elements= var.split(File::Separator)
26
- path_elements.delete('')
27
-
28
- tmp_hsh= {}
29
- current_obj= nil
30
-
31
- path_elements.count.times { |index|
32
-
33
- key_str= path_elements[index]
34
- (current_obj ||= tmp_hsh)
35
- current_obj[key_str]= {}
36
- current_obj= current_obj[key_str] unless index == (path_elements.count-1)
37
-
38
- }
39
-
40
- current_obj[ path_elements.last ]= JSON.parse File.read file_path
41
-
42
- opts[:out].deep_merge!(tmp_hsh)
43
-
44
- return nil
45
- end
46
-
47
- end
48
- alias :mount_json :mount_json_files
49
-
50
- end
51
-
52
- extend JSONFN
53
-
54
- end
@@ -1 +0,0 @@
1
- test: this
@@ -1,59 +0,0 @@
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
- [:r,:folder,:dir,:directory].each do |sym|
11
- opts[:root] ||= opts.delete(sym)
12
- end
13
- opts[:root] ||= Configer.pwd
14
-
15
- opts[:out] ||= opts.delete(:o) || opts.delete(:to) || Configer::Object
16
- raise(ArgumentError,"out/to must point to hashlike object") unless opts[:out].class <= ::Hash
17
- opts[:out].__send__ :extend, HashExtension unless opts[:out].respond_to?(:deep_merge!)
18
-
19
- Dir.glob( File.join( File.absolute_path(opts[:root]), "**","*.{yaml,yml}" ) ).each do |file_path|
20
-
21
- var= file_path.sub(opts[:root],"").split('.')
22
- var.pop
23
- var= var.join('.')
24
-
25
- path_elements= var.split(File::Separator)
26
- path_elements.delete('')
27
-
28
- tmp_hsh= {}
29
- current_obj= nil
30
-
31
- path_elements.count.times { |index|
32
-
33
- key_str= path_elements[index]
34
- (current_obj ||= tmp_hsh)
35
- current_obj[key_str]= {}
36
- current_obj= current_obj[key_str] unless index == (path_elements.count-1)
37
-
38
- }
39
-
40
- method_to_call = YAML.respond_to?(:safe_load) ? :safe_load : :load
41
- current_obj[ path_elements.last ]= YAML.public_send(
42
- method_to_call,
43
- File.read(file_path)
44
- )
45
-
46
- opts[:out].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
- extend YamlFN
58
-
59
- end
@@ -1 +0,0 @@
1
- puts 'Hello PMIP 0.3.2! - Please see http://code.google.com/p/pmip/ for full instructions and plugin helper bundles.'
@@ -1,11 +0,0 @@
1
- require "configer"
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 }
10
-
11
- config_obj= {}
@@ -1 +0,0 @@
1
- {"hello":"world"}
@@ -1 +0,0 @@
1
- hello: world
@@ -1,12 +0,0 @@
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">>>>
@@ -1,5 +0,0 @@
1
- $TEST = true
2
- require 'configer'
3
-
4
- # var = Configer::Object.new
5
- # var.hello = 'world'