loader 1.2.6 → 1.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2437076db69c76c793a5420f7b6e29e2ee1981e0
4
- data.tar.gz: 2a83311b0593eb2c31941bf275cf074500355dc2
3
+ metadata.gz: baa86c000a57bb154c384914994c745e77644ab0
4
+ data.tar.gz: 24193f8d91aae65f61f442d31af73d2c76dd0c46
5
5
  SHA512:
6
- metadata.gz: c27ed6f273f0bd3e909c63e0fc4ff312089c1ffb8257714ba0e009ce52c6acf043e437ff8005a9388c83c9f01c86ab961cd40b1a646b891fab87a335f7d23c49
7
- data.tar.gz: f5d7645769cce9783b88044d015899025ba4e1e52c4dc63c0f77591b35c9b581bf64511abb115fe4e45a11215375d6ce515b27ffa652628b39ef3e3da24249e3
6
+ metadata.gz: f8b8356364117953e9d8df97118aac1f00ae004d9ee5e6037370e7bbc5058f3538fb55f376abc5b07dc54334e4e1fe7cb7c143f367fbd188df3131768eaa901d
7
+ data.tar.gz: bf5f3705405f2c3f5807128cd410e8f89ff9fd8094c9fa4aaa13e81dce3355c57527289bafe3f2e706fa8606430f67a849ed10f0ebbe1343dc420f17cbbe8718
data/Gemfile CHANGED
@@ -1,2 +1,2 @@
1
- source "http://rubygems.org"
1
+ source :rubygems
2
2
  gemspec
data/LICENSE CHANGED
@@ -1,20 +1,20 @@
1
- The MIT License (MIT)
1
+ Copyright (c) 2013 Adam Luzsi
2
2
 
3
- Copyright (c) 2014 Adam Luzsi
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
4
10
 
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
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
11
13
 
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.
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -20,7 +20,8 @@ The end goal is to make an easy ruby file loader for gems. So Dir.pwd do not aff
20
20
 
21
21
  ### Examples
22
22
 
23
- load relative directory (not based on Dir.pwd)
23
+ load relative directory (not based on Dir.pwd but the caller files position)
24
+ if you pass multiple string as argument it will be joined by file separator that the OS use
24
25
 
25
26
  ```ruby
26
27
 
@@ -32,12 +33,16 @@ load relative directory (not based on Dir.pwd)
32
33
 
33
34
  # for recursive use try the following
34
35
  require_relative_directory "lib", :r
35
- ## or
36
+
37
+ # or
36
38
  require_relative_directory_r "lib"
37
39
 
40
+ # or
41
+ require_relative_directory "lib",r: true
42
+
38
43
  ```
39
44
 
40
- Additional Syntax for caller magic
45
+ Additional Syntax for caller magics
41
46
 
42
47
  ```ruby
43
48
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.6
1
+ 1.3.1
@@ -0,0 +1 @@
1
+ puts __FILE__
@@ -0,0 +1 @@
1
+ puts __FILE__
@@ -0,0 +1 @@
1
+ puts __FILE__
@@ -0,0 +1 @@
1
+ puts __FILE__
data/examples/meta.rb ADDED
@@ -0,0 +1,18 @@
1
+ require_relative "../lib/loader"
2
+
3
+ puts Loader.meta "examples","lib","**","meta"
4
+ #> {"asdf"=>{"else"=>{"world"=>"hello"}, "stuff"=>{"hello"=>"world"}}}
5
+
6
+ puts Loader.meta root: File.expand_path(File.dirname(__FILE__))
7
+ #> {"asdf"=>{"else"=>{"world"=>"hello"}, "stuff"=>{"hello"=>"world"}}}
8
+
9
+
10
+ puts Loader.meta "lib","**","meta",
11
+ root: File.expand_path(File.dirname(__FILE__))
12
+ #> {"asdf"=>{"else"=>{"world"=>"hello"}, "stuff"=>{"hello"=>"world"}}}
13
+
14
+ puts Loader.meta absolute: File.expand_path(File.join(File.dirname(__FILE__),"lib","**","meta"))
15
+ #> {"asdf"=>{"else"=>{"world"=>"hello"}, "stuff"=>{"hello"=>"world"}}}
16
+
17
+ puts Loader.metaloader_framework root: File.expand_path(File.dirname(__FILE__))
18
+ #> {"asdf"=>{"else"=>{"world"=>"hello"}, "stuff"=>{"hello"=>"world"}}}
@@ -1,24 +1,7 @@
1
1
  require_relative "../lib/loader"
2
2
 
3
+ #> require the ruby files from lib
3
4
  require_directory "lib"
4
- # one of the file has a "puts \"hello world!\"" that will run on load
5
- #> hello world!
6
5
 
7
- puts Loader.meta "examples","lib","**","meta"
8
- #> {"asdf"=>{"else"=>{"world"=>"hello"}, "stuff"=>{"hello"=>"world"}}}
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"}}}
22
-
23
- require_directory "lib", :r #> recursive
24
- #> hello world! from stuff.rb
6
+ #> require the ruby files from and under to lib (recursive)
7
+ require_directory_r "lib"
data/lib/loader.rb CHANGED
@@ -3,7 +3,6 @@ module Loader
3
3
 
4
4
  require "yaml"
5
5
 
6
- require File.join(File.dirname(__FILE__),"loader","array")
7
6
  require File.join(File.dirname(__FILE__),"loader","hash")
8
7
  require File.join(File.dirname(__FILE__),"loader","meta")
9
8
  require File.join(File.dirname(__FILE__),"loader","require")
data/lib/loader/hash.rb CHANGED
@@ -1,29 +1,19 @@
1
1
  module Loader
2
2
  module HashEXT
3
+ class << self
3
4
 
4
- # Returns a new hash with +self+ and +other_hash+ merged recursively.
5
- #
6
- # h1 = {:x => {:y => [4,5,6]}, :z => [7,8,9]}
7
- # h2 = {:x => {:y => [7,8,9]}, :z => "xyz"}
8
- #
9
- # h1.deep_merge(h2) #=> { :x => {:y => [7, 8, 9]}, :z => "xyz" }
10
- # h2.deep_merge(h1) #=> { :x => {:y => [4, 5, 6]}, :z => [7, 8, 9] }
11
- def deep_merge(other_hash)
12
- dup.deep_merge!(other_hash)
13
- end
14
-
15
- alias :+ :deep_merge unless method_defined? :deep_merge
5
+ def deep_merge(self_hash,other_hash)
6
+ deep_merge!(self_hash.dup,other_hash)
7
+ end
16
8
 
17
- # Same as +deep_merge+, but modifies +self+.
18
- def deep_merge!(other_hash)
19
- other_hash.each_pair do |k,v|
20
- tv = self[k]
21
- self[k] = tv.is_a?(Hash) && v.is_a?(Hash) ? tv.deep_merge(v) : v
9
+ def deep_merge!(self_hash,other_hash)
10
+ other_hash.each_pair do |k,v|
11
+ tv = self_hash[k]
12
+ self_hash[k] = tv.is_a?(::Hash) && v.is_a?(::Hash) ? deep_merge(tv,v) : v
13
+ end
14
+ self_hash
22
15
  end
23
- self
24
- end
25
16
 
17
+ end
26
18
  end
27
- end
28
-
29
- Hash.__send__ :include, Loader::HashEXT
19
+ end
data/lib/loader/meta.rb CHANGED
@@ -108,7 +108,7 @@ module Loader
108
108
 
109
109
  end
110
110
 
111
- target_config_hash.deep_merge! Loader.meta( absolute: lib_folder )
111
+ HashEXT.deep_merge! target_config_hash, Loader.meta( absolute: lib_folder )
112
112
 
113
113
  # update by config
114
114
  begin
@@ -157,7 +157,7 @@ module Loader
157
157
  config_yaml_paths.each do |one_yaml_file_path|
158
158
  begin
159
159
  yaml_data= YAML.load(File.open(one_yaml_file_path))
160
- target_config_hash.deep_merge!(yaml_data)
160
+ HashEXT.deep_merge!(target_config_hash,yaml_data)
161
161
 
162
162
  unless environment.nil?
163
163
  if one_yaml_file_path.include?(environment.to_s)
@@ -197,7 +197,10 @@ module Loader
197
197
  # yaml file name as key and the folder as the category
198
198
  def meta( *args )
199
199
 
200
- options= args.extract_class!(Hash)[0]
200
+ options= args.select{|e|(e.class <= ::Hash)}
201
+ args -= options
202
+ options= Hash[*options]
203
+
201
204
  options ||= {}
202
205
 
203
206
  if options[:absolute].nil?
@@ -2,51 +2,42 @@ module Loader
2
2
 
3
3
  module ObjectRequireEXT
4
4
 
5
- # Offline repo activate
6
- #def mount_modules(target_folder= File.join(Dir.pwd,"{module,modules}","{gem,gems}") )
7
- # Dir.glob(File.join(target_folder,"**","lib")).select{|f| File.directory?(f)}.each do |one_path|
8
- # $LOAD_PATH.unshift one_path
9
- # end
10
- #end
11
-
12
5
  # require sender relative directory's files
13
6
  # return the directory and the sub directories file names (rb/ru)
14
- def require_relative_directory( folder, *args )
7
+ def require_relative_directory *args
8
+
9
+ folder= args.select{|e|(e.class <= ::String)}.join(File::Separator)
10
+ opts= Hash[*args.select{|e|(e.class <= ::Hash)}]
11
+ args= args.select{|e|(e.class <= ::Symbol)}
15
12
 
16
- recursive= nil
17
- [:recursive,:r, :R, 'r', 'R', '-r', '-R'].each{|e| args.include?(e) ? recursive ||= true : nil }
13
+ opts[:recursive] ||= opts.delete(:r) || opts.delete(:R) || !([:recursive,:r, :R,].select{|e| args.include?(e)}.empty?)
14
+ opts[:recursive] = !!opts[:recursive]
18
15
 
19
- # opts[:extension] ||= opts[:extensions] || opts[:ex] || opts[:e] || []
20
- # raise(ArgumentError,"invalid extension object, must be array like") unless opts[:extension].class <= Array
16
+ opts[:caller_folder] ||= opts.delete(:f) || opts.delete(:folder) || Loader.caller_folder
21
17
 
22
18
  unless folder.to_s[0] == File::Separator
23
- folder= [Loader.caller_folder,folder]
19
+ folder= [opts[:caller_folder],folder]
24
20
  end
25
21
 
26
- path_parts= [*folder]
27
- if recursive
28
- path_parts.push("**")
22
+ #> recursive option
23
+ begin
24
+ path_parts= [*folder]
25
+ if opts[:recursive]
26
+ path_parts.push("**")
27
+ end
28
+ path_parts.push("*.{rb,ru}")
29
29
  end
30
- path_parts.push("*.{rb,ru}")
31
30
 
32
- return_value= false
33
- Dir.glob(File.join(*path_parts)).each do |one_path|
34
- require(one_path) ? return_value=( true ) : nil
35
- end
31
+ return Dir.glob(File.join(*path_parts)).sort_by{|e| e.split(File::Separator).size }.map { |one_path|
32
+ require(one_path)
33
+ }.include?(true)
36
34
 
37
- return return_value
38
35
  end
39
36
 
40
37
  alias :require_directory :require_relative_directory
41
38
 
42
- def require_relative_directory_r folder
43
-
44
- unless folder.to_s[0] == File::Separator
45
- folder= File.join(Loader.caller_folder,folder)
46
- end
47
-
48
- require_relative_directory folder,:r
49
-
39
+ def require_relative_directory_r *args
40
+ require_relative_directory *args, r: true, f: Loader.caller_folder
50
41
  end
51
42
  alias :require_directory_r :require_relative_directory_r
52
43
 
data/loader.gemspec CHANGED
@@ -12,7 +12,6 @@ Gem::Specification.new do |spec|
12
12
  spec.description = %q{ dsl for gem helper calls such like relative folder calls that independ on the Dir.pwd or File.expand tricks and config loader stuffs, Check out the GIT! }
13
13
  spec.summary = %q{DSL for helping make file require easy just like build configuration objects }
14
14
  spec.homepage = "https://github.com/adamluzsi/loader"
15
- spec.license = "MIT"
16
15
 
17
16
  spec.files = `git ls-files`.split($/)
18
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
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.2.6
4
+ version: 1.3.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-05-07 00:00:00.000000000 Z
11
+ date: 2014-05-08 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: " dsl for gem helper calls such like relative folder calls that independ
14
14
  on the Dir.pwd or File.expand tricks and config loader stuffs, Check out the GIT! "
@@ -24,13 +24,16 @@ files:
24
24
  - README.md
25
25
  - Rakefile
26
26
  - VERSION
27
+ - examples/lib/asdf/level2.rb
27
28
  - examples/lib/asdf/meta/else.yml
29
+ - examples/lib/asdf/meta/level3.rb
28
30
  - examples/lib/asdf/meta/stuff.yml
29
- - examples/lib/asdf/stuff.rb
31
+ - examples/lib/level1_1.rb
32
+ - examples/lib/level1_2.rb
33
+ - examples/meta.rb
30
34
  - examples/simple_require.rb
31
35
  - files.rb
32
36
  - lib/loader.rb
33
- - lib/loader/array.rb
34
37
  - lib/loader/hash.rb
35
38
  - lib/loader/meta.rb
36
39
  - lib/loader/require.rb
@@ -38,8 +41,7 @@ files:
38
41
  - test/sub/test2.rb
39
42
  - test/test.rb
40
43
  homepage: https://github.com/adamluzsi/loader
41
- licenses:
42
- - MIT
44
+ licenses: []
43
45
  metadata: {}
44
46
  post_install_message:
45
47
  rdoc_options: []
@@ -1 +0,0 @@
1
- puts "hello world!"
data/lib/loader/array.rb DELETED
@@ -1,26 +0,0 @@
1
- module Loader
2
- module ArrayEXT
3
-
4
- # generate params structure from array
5
- # return_array
6
- def extract_class! class_name
7
-
8
- if class_name.class != Class
9
- raise ArgumentError, "parameter must be a class name"
10
- end
11
-
12
- return_value= self.map { |element|
13
- if element.class == class_name
14
- element
15
- end
16
- }.uniq - [ nil ]
17
- return_value.each{|e| self.delete(e) }
18
-
19
- return return_value
20
-
21
- end unless method_defined? :extract_class!
22
-
23
- end
24
- end
25
-
26
- Array.__send__ :include, Loader::ArrayEXT