loader 1.0.0.pre.beta → 1.0.1
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 +8 -8
- data/README.md +21 -1
- data/VERSION +1 -1
- data/examples/lib/asdf/meta/else.yml +1 -0
- data/examples/simple_require.rb +17 -2
- data/lib/loader.rb +1 -0
- data/lib/loader/array.rb +45 -0
- data/lib/loader/meta.rb +123 -105
- data/lib/loader/require.rb +3 -28
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YjJiYmVkMGE1NDBkNDAwOTI1MGE0NjYxNTExMmM4NzYzN2Y4ZDE5OQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MWMyMmEyZWVlMTA3YWQ4ODYzNjU2NTc1NDk3OTM3Zjc3ODUwZWIwYg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZGI0ZTUwMDgyM2IzMzc2OGY2NmFlMTQxMGY4NDQyZTYxMzllYTM3NjcxYzdh
|
10
|
+
ZDIxZTE1ZTNiZTMyYmM1NmMyZTk4NzA5MTlkNDUyOTMwMjFkZDI3YjgwMGIx
|
11
|
+
YmY2ZDY5YzIyMmYwYmQ0YjMzYTE2NDliNzlkNTQwYjJjNmU5MDA=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YTU4YjY0YmIzZTcyZWQ1MTFhMDk4MjA4MTlmMjc4YWFhMDlhMGRiYjU5NmVk
|
14
|
+
N2Y2YTgxZWMxMGFjZDg3OTAwN2FhZmJhOWM2ZGQwODExMzg2Mzc1YjRjMWM4
|
15
|
+
MDgyNDRmYTgzZTJjZWM3ZTQ2YjIyNTllZDI1YTVmODY1NzU0Nzc=
|
data/README.md
CHANGED
@@ -3,4 +3,24 @@ loader
|
|
3
3
|
|
4
4
|
Ruby require loader gem with caller tricks
|
5
5
|
Meta config file loaders and much more
|
6
|
-
|
6
|
+
|
7
|
+
### Introduction
|
8
|
+
|
9
|
+
Okey, before you even think about use this gem, let's say this gem only for lazy ones...
|
10
|
+
the basic idea is to have an easy to use relative require system with yaml config file loading
|
11
|
+
into a constant, maybe into some othere config specific gem that make config objects from hash.
|
12
|
+
|
13
|
+
The fun part is , that this stuffs can be used in making a new gem,
|
14
|
+
because it do not depend on the Dir.pwd or
|
15
|
+
the File Expand tricks
|
16
|
+
|
17
|
+
the use cases are hell simple , like:
|
18
|
+
|
19
|
+
# return and load the meta files from
|
20
|
+
# the lib/**/meta and return the hash obj build from the yamls
|
21
|
+
Loader.meta
|
22
|
+
|
23
|
+
# load all rb file that was not loaded already
|
24
|
+
# from that relative folder
|
25
|
+
require_relative_directory "folder_name"
|
26
|
+
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.1
|
@@ -0,0 +1 @@
|
|
1
|
+
world: hello
|
data/examples/simple_require.rb
CHANGED
@@ -1,6 +1,21 @@
|
|
1
1
|
require_relative "../lib/loader"
|
2
2
|
|
3
|
-
|
3
|
+
require_relative_directory "lib"
|
4
|
+
# one of the file has a "puts \"hello world!\"" that will run on load
|
5
|
+
#> hello world!
|
4
6
|
|
5
|
-
puts Loader.meta
|
7
|
+
puts Loader.meta "examples","lib","**","meta"
|
8
|
+
#> {"asdf"=>{"else"=>{"world"=>"hello"}, "stuff"=>{"hello"=>"world"}}}
|
6
9
|
|
10
|
+
puts Loader.meta root: File.expand_path(File.dirname(__FILE__))
|
11
|
+
#> {"asdf"=>{"else"=>{"world"=>"hello"}, "stuff"=>{"hello"=>"world"}}}
|
12
|
+
|
13
|
+
puts Loader.meta "lib","**","meta",
|
14
|
+
root: File.expand_path(File.dirname(__FILE__))
|
15
|
+
#> {"asdf"=>{"else"=>{"world"=>"hello"}, "stuff"=>{"hello"=>"world"}}}
|
16
|
+
|
17
|
+
puts Loader.meta absolute: File.expand_path(File.join(File.dirname(__FILE__),"lib","**","meta"))
|
18
|
+
#> {"asdf"=>{"else"=>{"world"=>"hello"}, "stuff"=>{"hello"=>"world"}}}
|
19
|
+
|
20
|
+
puts Loader.metaloader_framework root: File.expand_path(File.dirname(__FILE__))
|
21
|
+
#> {"asdf"=>{"else"=>{"world"=>"hello"}, "stuff"=>{"hello"=>"world"}}}
|
data/lib/loader.rb
CHANGED
data/lib/loader/array.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
class Array
|
2
|
+
|
3
|
+
# remove n. element from the end
|
4
|
+
# and return a new object
|
5
|
+
def pinch n=1
|
6
|
+
return self[0..(self.count-(n+1))]
|
7
|
+
end unless method_defined? :pinch
|
8
|
+
|
9
|
+
# remove n. element from the end
|
10
|
+
# and return the original object
|
11
|
+
def pinch! n=1
|
12
|
+
n.times do
|
13
|
+
self.pop
|
14
|
+
end
|
15
|
+
return self
|
16
|
+
end unless method_defined? :pinch!
|
17
|
+
|
18
|
+
# return boolean by other array
|
19
|
+
# all element included or
|
20
|
+
# not in the target array
|
21
|
+
def contain?(oth_array)#anothere array
|
22
|
+
(oth_array & self) == oth_array
|
23
|
+
end unless method_defined? :contain?
|
24
|
+
alias :contains? :contain? unless method_defined? :contain?
|
25
|
+
|
26
|
+
# generate params structure from array
|
27
|
+
# return_array
|
28
|
+
def extract_class! class_name
|
29
|
+
|
30
|
+
if class_name.class != Class
|
31
|
+
raise ArgumentError, "parameter must be a class name"
|
32
|
+
end
|
33
|
+
|
34
|
+
return_value= self.map { |element|
|
35
|
+
if element.class == class_name
|
36
|
+
element
|
37
|
+
end
|
38
|
+
}.uniq - [ nil ]
|
39
|
+
return_value.each{|e| self.delete(e) }
|
40
|
+
|
41
|
+
return return_value
|
42
|
+
|
43
|
+
end unless method_defined? :extract_class!
|
44
|
+
|
45
|
+
end
|
data/lib/loader/meta.rb
CHANGED
@@ -20,65 +20,30 @@ module Loader
|
|
20
20
|
# defaults
|
21
21
|
begin
|
22
22
|
|
23
|
-
root_folder
|
24
|
-
|
25
|
-
target_config_hash = opts[:config]
|
26
|
-
lib_folder = opts[:lib_folder]
|
27
|
-
config_folder = opts[:config_folder]
|
23
|
+
root_folder = opts[:root]
|
24
|
+
root_folder ||= caller_root_folder
|
28
25
|
|
26
|
+
target_config_hash = opts[:config_obj]
|
27
|
+
target_config_hash ||= Hash.new
|
29
28
|
|
30
|
-
|
31
|
-
root_folder ||= Dir.pwd
|
32
|
-
target_config_hash ||= Application.config
|
33
|
-
|
29
|
+
lib_folder = opts[:lib_folder]
|
34
30
|
lib_folder ||= File.join(root_folder,"{lib,libs}","**","meta")
|
31
|
+
|
32
|
+
config_folder = opts[:config_folder]
|
35
33
|
config_folder ||= File.join(root_folder,"{config,conf}","**")
|
36
34
|
|
37
|
-
|
38
|
-
|
39
|
-
target_config_hash= Hash.new()
|
40
|
-
end
|
35
|
+
input_config_file = opts[:config_file]
|
36
|
+
environment = opts[:environment]
|
41
37
|
|
42
38
|
end
|
43
39
|
|
44
|
-
|
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
|
40
|
+
target_config_hash.deep_merge! Loader.meta( absolute: lib_folder )
|
75
41
|
|
76
42
|
# update by config
|
77
43
|
begin
|
78
44
|
|
79
45
|
# get config files
|
80
46
|
begin
|
81
|
-
|
82
47
|
config_yaml_paths= Array.new()
|
83
48
|
Dir.glob(File.join(config_folder,"*.{yaml,yml}")).uniq.each do |one_path|
|
84
49
|
|
@@ -106,13 +71,13 @@ module Loader
|
|
106
71
|
end
|
107
72
|
|
108
73
|
# params config load
|
109
|
-
unless
|
74
|
+
unless input_config_file.nil?
|
110
75
|
begin
|
111
|
-
path= File.expand_path(
|
76
|
+
path= File.expand_path(input_config_file,"r")
|
112
77
|
File.open(path)
|
113
78
|
config_yaml_paths.push(path)
|
114
79
|
rescue Exception
|
115
|
-
config_yaml_paths.push(
|
80
|
+
config_yaml_paths.push(input_config_file)
|
116
81
|
end
|
117
82
|
end
|
118
83
|
|
@@ -123,8 +88,8 @@ module Loader
|
|
123
88
|
yaml_data= YAML.load(File.open(one_yaml_file_path))
|
124
89
|
target_config_hash.deep_merge!(yaml_data)
|
125
90
|
|
126
|
-
unless
|
127
|
-
if one_yaml_file_path.include?(
|
91
|
+
unless environment.nil?
|
92
|
+
if one_yaml_file_path.include?(environment.to_s)
|
128
93
|
break
|
129
94
|
end
|
130
95
|
end
|
@@ -164,68 +129,121 @@ module Loader
|
|
164
129
|
|
165
130
|
end
|
166
131
|
|
167
|
-
|
132
|
+
# you can give optional file names that will be searched for
|
133
|
+
def caller_root(*args)
|
168
134
|
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
135
|
+
what_can_be_in_the_root= %w[
|
136
|
+
gemfile Gemfile GemFile
|
137
|
+
rakefile Rakefile RakeFile
|
138
|
+
config.ru README.md ] + args.map{|e|e.to_s}
|
173
139
|
|
140
|
+
folder_path= caller_folder(2).split(File::Separator)
|
174
141
|
|
142
|
+
loop do
|
143
|
+
|
144
|
+
Dir.glob(File.join(folder_path.join(File::Separator),"*")).map do |element|
|
145
|
+
if !File.directory?(element)
|
146
|
+
if what_can_be_in_the_root.include? element.split(File::Separator).last
|
147
|
+
return folder_path.join(File::Separator)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
if folder_path.count != 0
|
153
|
+
folder_path.pop
|
154
|
+
else
|
155
|
+
return nil
|
156
|
+
end
|
157
|
+
|
158
|
+
end
|
175
159
|
|
176
160
|
end
|
177
161
|
|
162
|
+
alias :caller_root_folder :caller_root
|
163
|
+
|
178
164
|
# load meta folders rb files
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
#
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
165
|
+
# by default it will be the caller objects root folder (app root)
|
166
|
+
# else you must set with hand the path from your app root
|
167
|
+
# example:
|
168
|
+
#
|
169
|
+
# Loader.meta
|
170
|
+
#
|
171
|
+
# Loader.meta 'lib','**','config_files'
|
172
|
+
#
|
173
|
+
# Loader.meta root: "/home/...../my_app",'lib','**','meta'
|
174
|
+
#
|
175
|
+
# Loader.meta 'lib','**','meta',
|
176
|
+
# root: "/home/...../my_app"
|
177
|
+
#
|
178
|
+
# You can use the "absolute: string_path" option just alike so it wont try find your
|
179
|
+
# app root folder
|
180
|
+
#
|
181
|
+
# All will return a Hash obj with the loaded meta configs based on the
|
182
|
+
# yaml file name as key and the folder as the category
|
183
|
+
def meta( *args )
|
184
|
+
|
185
|
+
options= args.extract_class!(Hash)[0]
|
186
|
+
options ||= {}
|
187
|
+
|
188
|
+
if options[:absolute].nil?
|
189
|
+
|
190
|
+
if args.empty?
|
191
|
+
args= ["lib","**","meta"]
|
192
|
+
end
|
193
|
+
|
194
|
+
if !options[:root].nil?
|
195
|
+
root_folder_path= options[:root]
|
196
|
+
else
|
197
|
+
root_folder_path= caller_root_folder
|
198
|
+
end
|
199
|
+
|
200
|
+
args.unshift(root_folder_path)
|
201
|
+
|
202
|
+
else
|
203
|
+
args= [options[:absolute]]
|
204
|
+
end
|
205
|
+
|
206
|
+
target_folder= File.join(*args)
|
207
|
+
|
208
|
+
# load ruby files from meta
|
209
|
+
begin
|
210
|
+
Dir.glob( File.join(target_folder,"*.{rb,ru}") ).each do |one_rb_file|
|
211
|
+
require one_rb_file
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
# load yaml files elements
|
216
|
+
begin
|
217
|
+
|
218
|
+
target_config_hash= Hash.new
|
219
|
+
Dir.glob(File.join(target_folder,"*.{yaml,yml}")).each do |config_object|
|
220
|
+
|
221
|
+
# defaults
|
222
|
+
begin
|
223
|
+
config_name_elements= config_object.split(File::SEPARATOR)
|
224
|
+
|
225
|
+
type= config_name_elements.pop.split('.')[0]
|
226
|
+
config_name_elements.pop
|
227
|
+
|
228
|
+
category= config_name_elements.pop
|
229
|
+
yaml_data= YAML.load(File.open(config_object))
|
230
|
+
end
|
231
|
+
|
232
|
+
# processing
|
233
|
+
begin
|
234
|
+
target_config_hash[category] ||= {}
|
235
|
+
target_config_hash[category][type] ||= {}
|
236
|
+
target_config_hash[category][type] = yaml_data
|
237
|
+
end
|
238
|
+
|
239
|
+
end
|
240
|
+
|
241
|
+
end
|
242
|
+
|
243
|
+
# return data
|
244
|
+
begin
|
245
|
+
return target_config_hash
|
246
|
+
end
|
229
247
|
|
230
248
|
end
|
231
249
|
|
data/lib/loader/require.rb
CHANGED
@@ -18,36 +18,11 @@ module Kernel
|
|
18
18
|
# return the directory and the sub directories file names (rb/ru)
|
19
19
|
def require_relative_directory(folder)
|
20
20
|
|
21
|
-
|
22
|
-
|
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
|
-
|
21
|
+
Dir.glob(File.join(Loader.caller_folder,folder,"**","*.{rb,ru}")).each do |one_path|
|
22
|
+
require one_path
|
43
23
|
end
|
44
24
|
|
45
|
-
|
46
|
-
begin
|
47
|
-
return Dir.glob(File.join(path,folder,"**","*.{rb,ru}")).each do |one_path|
|
48
|
-
require one_path
|
49
|
-
end
|
50
|
-
end
|
25
|
+
return nil
|
51
26
|
|
52
27
|
end
|
53
28
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: loader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
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-02-
|
11
|
+
date: 2014-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: ! ' Require dsl, relative calls that depend on the caller methods position
|
14
14
|
and stuffs like that. '
|
@@ -23,11 +23,13 @@ files:
|
|
23
23
|
- README.md
|
24
24
|
- Rakefile
|
25
25
|
- VERSION
|
26
|
+
- examples/lib/asdf/meta/else.yml
|
26
27
|
- examples/lib/asdf/meta/stuff.yml
|
27
28
|
- examples/lib/asdf/stuff.rb
|
28
29
|
- examples/simple_require.rb
|
29
30
|
- files.rb
|
30
31
|
- lib/loader.rb
|
32
|
+
- lib/loader/array.rb
|
31
33
|
- lib/loader/hash.rb
|
32
34
|
- lib/loader/meta.rb
|
33
35
|
- lib/loader/require.rb
|
@@ -48,9 +50,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
48
50
|
version: '0'
|
49
51
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
52
|
requirements:
|
51
|
-
- - ! '
|
53
|
+
- - ! '>='
|
52
54
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
55
|
+
version: '0'
|
54
56
|
requirements: []
|
55
57
|
rubyforge_project:
|
56
58
|
rubygems_version: 2.2.1
|