loader 1.0.0.pre.beta

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ Y2UyZDE1NzFhNGJlN2RiYTVlZTFmZmUzMzc1YTg0ZGUwOGNjYjM0Zg==
5
+ data.tar.gz: !binary |-
6
+ OGM3OTBhYjBmYzM5ZDc1MjU5YTFiZWRiZjM1YWEyY2ZkN2MzYmI0NA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ OGMxMzdlNjI5MWY3N2IyMDBiNzIzZDQ0MGEyNzUwOWViZmU3NGE0ZGZmNTFl
10
+ MmFjMzIxMDZjZDExNzljZDM2N2EwNGI1NGEyY2IzZGY3ZTRkMjk5MzEzODY4
11
+ ZDc0OGI0MDY4NjZiOGVhNzlmOGUyZGZmYTg0ZjkzMmE4YTM0NWM=
12
+ data.tar.gz: !binary |-
13
+ NTY4M2U5YTYyZDVmNmE5YmZkZTUxMjA0OTZhOTIyOWZlMWI0YWZiNGUzNmNh
14
+ N2MyZjI2ZWRkNWI4NmM4Yjk4ZDM4Nzg5MDA5MzllMGI5YWU5ZTQwOGRiODAw
15
+ MDRmZTVmYTgwYmFjZTA2MzU5NDk2NjM5NzBhOTY4MmZlYjdkM2I=
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "http://rubygems.org"
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Adam Luzsi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,6 @@
1
+ loader
2
+ ======
3
+
4
+ Ruby require loader gem with caller tricks
5
+ Meta config file loaders and much more
6
+ Description will be upgraded
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require File.join "bundler","gem_tasks"
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0-beta
@@ -0,0 +1 @@
1
+ hello: world
@@ -0,0 +1 @@
1
+ puts "hello world!"
@@ -0,0 +1,6 @@
1
+ require_relative "../lib/loader"
2
+
3
+ #require_relative_directory "lib"
4
+
5
+ puts Loader.meta().inspect
6
+
data/files.rb ADDED
@@ -0,0 +1,24 @@
1
+ ### Get Files from dir
2
+ begin
3
+
4
+ files_to_be_loaded = %w[version.rb]
5
+
6
+ SpecFiles= Array.new
7
+
8
+ Dir[File.expand_path(File.join(File.dirname(__FILE__),"**","*"))].sort.uniq.each do |one_file_name|
9
+ one_file_name = File.expand_path one_file_name
10
+ file_name = one_file_name[(File.expand_path(File.dirname(__FILE__)).to_s.length+1)..(one_file_name.length-1)]
11
+
12
+ if !one_file_name.include?("pkg")
13
+ if !File.directory? file_name
14
+ SpecFiles.push file_name
15
+ STDOUT.puts file_name if $DEBUG
16
+ if files_to_be_loaded.include? one_file_name.split(File::SEPARATOR).last
17
+ load one_file_name
18
+ end
19
+ end
20
+ end
21
+
22
+ end
23
+
24
+ end
data/lib/loader.rb ADDED
@@ -0,0 +1,10 @@
1
+ #encoding: UTF-8
2
+ module Loader
3
+
4
+ require "yaml"
5
+
6
+ require File.join(File.dirname(__FILE__),"loader","require")
7
+ require File.join(File.dirname(__FILE__),"loader","meta")
8
+ require File.join(File.dirname(__FILE__),"loader","hash")
9
+
10
+ end
@@ -0,0 +1,84 @@
1
+ class Hash
2
+
3
+ # remove elements by keys,
4
+ # array of keys,
5
+ # hashTags,
6
+ # strings
7
+ def trim(*args)
8
+
9
+ args.each do |one_element|
10
+ case true
11
+
12
+ when one_element.class == Hash
13
+ begin
14
+ one_element.each do |key,value|
15
+ if self[key] == value
16
+ self.delete(key)
17
+ end
18
+ end
19
+ end
20
+
21
+ when one_element.class == Array
22
+ begin
23
+ one_element.each do |one_key|
24
+ self.delete(one_key)
25
+ end
26
+ end
27
+
28
+ when one_element.class == Symbol,
29
+ one_element.class == String
30
+ begin
31
+ self.delete(one_element)
32
+ end
33
+
34
+ end
35
+ end
36
+ return self
37
+
38
+ end unless method_defined? :trim
39
+
40
+ #pass single or array of keys, which will be removed, returning the remaining hash
41
+ def remove!(*keys)
42
+ keys.each{|key| self.delete(key) }
43
+ self
44
+ end unless method_defined? :remove!
45
+
46
+ #non-destructive version
47
+ def remove(*keys)
48
+ self.dup.remove!(*keys)
49
+ end unless method_defined? :remove
50
+
51
+ # Returns a new hash with +self+ and +other_hash+ merged recursively.
52
+ #
53
+ # h1 = {:x => {:y => [4,5,6]}, :z => [7,8,9]}
54
+ # h2 = {:x => {:y => [7,8,9]}, :z => "xyz"}
55
+ #
56
+ # h1.deep_merge(h2) #=> { :x => {:y => [7, 8, 9]}, :z => "xyz" }
57
+ # h2.deep_merge(h1) #=> { :x => {:y => [4, 5, 6]}, :z => [7, 8, 9] }
58
+ def deep_merge(other_hash)
59
+ dup.deep_merge!(other_hash)
60
+ end unless method_defined? :deep_merge
61
+
62
+ alias :+ :deep_merge unless method_defined? :deep_merge
63
+
64
+ # Same as +deep_merge+, but modifies +self+.
65
+ def deep_merge!(other_hash)
66
+ other_hash.each_pair do |k,v|
67
+ tv = self[k]
68
+ self[k] = tv.is_a?(Hash) && v.is_a?(Hash) ? tv.deep_merge(v) : v
69
+ end
70
+ self
71
+ end unless method_defined? :deep_merge!
72
+
73
+ # return bool that does the sub hash all element include the hash who call this or not
74
+ def deep_include?(sub_hash)
75
+ sub_hash.keys.all? do |key|
76
+ self.has_key?(key) && if sub_hash[key].is_a?(Hash)
77
+ self[key].is_a?(Hash) && self[key].deep_include?(sub_hash[key])
78
+ else
79
+ self[key] == sub_hash[key]
80
+ end
81
+ end
82
+ end unless method_defined? :deep_include?
83
+
84
+ end
@@ -0,0 +1,234 @@
1
+ module Loader
2
+ class << self
3
+
4
+
5
+
6
+ # gives you a basic meta load framework for easy config use (yaml)
7
+ # basic system is
8
+ #
9
+ # root folder:
10
+ # - config
11
+ # -| "YAML files" #> development.yaml
12
+ #
13
+ # - lib
14
+ # -- module_name
15
+ # --- meta
16
+ # ---| "YAML files" #> rack.yaml
17
+ #
18
+ def metaloader_framework(opts={})
19
+
20
+ # defaults
21
+ begin
22
+
23
+ root_folder = opts[:root]
24
+ override = opts[:override]
25
+ target_config_hash = opts[:config]
26
+ lib_folder = opts[:lib_folder]
27
+ config_folder = opts[:config_folder]
28
+
29
+
30
+ override ||= true
31
+ root_folder ||= Dir.pwd
32
+ target_config_hash ||= Application.config
33
+
34
+ lib_folder ||= File.join(root_folder,"{lib,libs}","**","meta")
35
+ config_folder ||= File.join(root_folder,"{config,conf}","**")
36
+
37
+ require "yaml"
38
+ if target_config_hash.class != Hash
39
+ target_config_hash= Hash.new()
40
+ end
41
+
42
+ end
43
+
44
+ # find elements
45
+ begin
46
+
47
+ #TODO meta DRY here!
48
+ Dir.glob(File.join(lib_folder,"*.{yaml,yml}")).each do |config_object|
49
+
50
+ # defaults
51
+ begin
52
+ config_name_elements= config_object.split(File::SEPARATOR)
53
+ type= config_name_elements.pop.split('.')[0]
54
+ config_name_elements.pop
55
+
56
+ category = config_name_elements.pop
57
+ tmp_hash = Hash.new()
58
+ yaml_data = YAML.load(File.open(config_object))
59
+ end
60
+
61
+ # processing
62
+ begin
63
+ if target_config_hash[category].nil?
64
+ target_config_hash[category]= { type => yaml_data }
65
+ else
66
+ unless override == false
67
+ target_config_hash[category][type]= yaml_data
68
+ end
69
+ end
70
+ end
71
+
72
+ end
73
+
74
+ end
75
+
76
+ # update by config
77
+ begin
78
+
79
+ # get config files
80
+ begin
81
+
82
+ config_yaml_paths= Array.new()
83
+ Dir.glob(File.join(config_folder,"*.{yaml,yml}")).uniq.each do |one_path|
84
+
85
+ case true
86
+
87
+ when one_path.downcase.include?('default')
88
+ config_yaml_paths[0]= one_path
89
+
90
+ when one_path.downcase.include?('development')
91
+ config_yaml_paths[1]= one_path
92
+
93
+ when one_path.downcase.include?('test')
94
+ config_yaml_paths[2]= one_path
95
+
96
+ when one_path.downcase.include?('production')
97
+ config_yaml_paths[3]= one_path
98
+
99
+ else
100
+ config_yaml_paths[config_yaml_paths.count]= one_path
101
+
102
+ end
103
+
104
+ end
105
+ config_yaml_paths.select!{|x| x != nil }
106
+ end
107
+
108
+ # params config load
109
+ unless Application.config_file.nil?
110
+ begin
111
+ path= File.expand_path(Application.config_file,"r")
112
+ File.open(path)
113
+ config_yaml_paths.push(path)
114
+ rescue Exception
115
+ config_yaml_paths.push(Application.config_file)
116
+ end
117
+ end
118
+
119
+ # load to last lvl environment
120
+ begin
121
+ config_yaml_paths.each do |one_yaml_file_path|
122
+ begin
123
+ yaml_data= YAML.load(File.open(one_yaml_file_path))
124
+ target_config_hash.deep_merge!(yaml_data)
125
+
126
+ unless Application.environment.nil?
127
+ if one_yaml_file_path.include?(Application.environment.to_s)
128
+ break
129
+ end
130
+ end
131
+ rescue Exception
132
+ end
133
+ end
134
+ end
135
+
136
+ end
137
+
138
+ return target_config_hash
139
+
140
+ end
141
+
142
+ def caller_folder integer_num= 1
143
+
144
+ # path create from caller
145
+ begin
146
+ path= caller[integer_num].split(".{rb,ru}:").first.split(File::Separator)
147
+ path= path[0..(path.count-2)]
148
+ end
149
+
150
+ # after formatting
151
+ begin
152
+
153
+ if !File.directory?(path.join(File::SEPARATOR))
154
+ path.pop
155
+ end
156
+ path= File.join(path.join(File::SEPARATOR))
157
+ if path != File.expand_path(path)
158
+ path= File.expand_path(path)
159
+ end
160
+
161
+ end
162
+
163
+ return path
164
+
165
+ end
166
+
167
+ def caller_root
168
+
169
+ sender_folder_path= caller_folder(2).split(File::Separator)
170
+ Dir.glob(sender_folder_path.join(File::Separator)).each do |e|
171
+ puts e
172
+ end
173
+
174
+
175
+
176
+ end
177
+
178
+ # load meta folders rb files
179
+ def meta( target_folder = nil )
180
+
181
+ caller_root
182
+
183
+ #target_folder ||= caller_folder
184
+ #
185
+ ## find elements
186
+ #begin
187
+ # Dir.glob( File.join(target_folder,"*.{rb,ru}") ).each do |one_rb_file|
188
+ # require one_rb_file
189
+ # end
190
+ #end
191
+ #
192
+ ## defaults
193
+ #begin
194
+ # target_config_hash= Hash.new()
195
+ #end
196
+ #
197
+ ## find elements
198
+ #begin
199
+ #
200
+ # Dir.glob(File.join(target_folder,"*.{yaml,yml}")).each do |config_object|
201
+ #
202
+ # # defaults
203
+ # begin
204
+ # config_name_elements= config_object.split(File::SEPARATOR)
205
+ # type= config_name_elements.pop.split('.')[0]
206
+ # config_name_elements.pop
207
+ # category= config_name_elements.pop
208
+ # tmp_hash= Hash.new()
209
+ # yaml_data= YAML.load(File.open(config_object))
210
+ # end
211
+ #
212
+ # # processing
213
+ # begin
214
+ # if target_config_hash[category].nil?
215
+ # target_config_hash[category]= { type => yaml_data }
216
+ # else
217
+ # target_config_hash[category][type]= yaml_data
218
+ # end
219
+ # end
220
+ #
221
+ # end
222
+ #
223
+ #end
224
+ #
225
+ ## return data
226
+ #begin
227
+ # return target_config_hash
228
+ #end
229
+
230
+ end
231
+
232
+
233
+ end
234
+ end
@@ -0,0 +1,54 @@
1
+ module Kernel
2
+
3
+ # Offline repo activate
4
+ #def mount_modules(target_folder= File.join(Dir.pwd,"{module,modules}","{gem,gems}") )
5
+ # Dir.glob(File.join(target_folder,"**","lib")).select{|f| File.directory?(f)}.each do |one_path|
6
+ # $LOAD_PATH.unshift one_path
7
+ # end
8
+ #end
9
+
10
+ # require by absolute path directory's files
11
+ def require_directory(folder)
12
+ Dir.glob(File.join(folder,"**","*.{rb,ru}")).each do |file_path|
13
+ require file_path
14
+ end
15
+ end
16
+
17
+ # require sender relative directory's files
18
+ # return the directory and the sub directories file names (rb/ru)
19
+ def require_relative_directory(folder)
20
+
21
+ # pre format
22
+ begin
23
+
24
+ # path create from caller
25
+ begin
26
+ path= caller[0].split(".{rb,ru}:").first.split(File::SEPARATOR)
27
+ path= path[0..(path.count-2)]
28
+ end
29
+
30
+ # after formatting
31
+ begin
32
+
33
+ if !File.directory?(path.join(File::SEPARATOR))
34
+ path.pop
35
+ end
36
+ path= File.join(path.join(File::SEPARATOR))
37
+ if path != File.expand_path(path)
38
+ path= File.expand_path(path)
39
+ end
40
+
41
+ end
42
+
43
+ end
44
+
45
+ # find elements
46
+ begin
47
+ return Dir.glob(File.join(path,folder,"**","*.{rb,ru}")).each do |one_path|
48
+ require one_path
49
+ end
50
+ end
51
+
52
+ end
53
+
54
+ end
data/loader.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+
3
+ require File.expand_path(File.join(File.dirname(__FILE__),"files.rb"))
4
+
5
+ ### Specification for the new Gem
6
+ Gem::Specification.new do |spec|
7
+
8
+ spec.name = "loader"
9
+ spec.version = File.open(File.join(File.dirname(__FILE__),"VERSION")).read.split("\n")[0].chomp.gsub(' ','')
10
+ spec.authors = ["Adam Luzsi"]
11
+ spec.email = ["adamluzsi@gmail.com"]
12
+ spec.description = %q{ Require dsl, relative calls that depend on the caller methods position and stuffs like that. }
13
+ spec.summary = %q{Simple require dsl Based on standard CRuby}
14
+ spec.homepage = "https://github.com/adamluzsi/loader"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = SpecFiles
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ ##=======Runtime-ENV================##
23
+ #spec.add_runtime_dependency "asdf", ['~>4.1.3']
24
+
25
+ ##=======Development-ENV============##
26
+ #spec.add_development_dependency "asdf",['~>4.1.3']
27
+
28
+ end
data/test/test.rb ADDED
File without changes
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: loader
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.pre.beta
5
+ platform: ruby
6
+ authors:
7
+ - Adam Luzsi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-02 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: ! ' Require dsl, relative calls that depend on the caller methods position
14
+ and stuffs like that. '
15
+ email:
16
+ - adamluzsi@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - Gemfile
22
+ - LICENSE
23
+ - README.md
24
+ - Rakefile
25
+ - VERSION
26
+ - examples/lib/asdf/meta/stuff.yml
27
+ - examples/lib/asdf/stuff.rb
28
+ - examples/simple_require.rb
29
+ - files.rb
30
+ - lib/loader.rb
31
+ - lib/loader/hash.rb
32
+ - lib/loader/meta.rb
33
+ - lib/loader/require.rb
34
+ - loader.gemspec
35
+ - test/test.rb
36
+ homepage: https://github.com/adamluzsi/loader
37
+ licenses:
38
+ - MIT
39
+ metadata: {}
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ! '>'
52
+ - !ruby/object:Gem::Version
53
+ version: 1.3.1
54
+ requirements: []
55
+ rubyforge_project:
56
+ rubygems_version: 2.2.1
57
+ signing_key:
58
+ specification_version: 4
59
+ summary: Simple require dsl Based on standard CRuby
60
+ test_files:
61
+ - test/test.rb
62
+ has_rdoc: