scout-gear 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5d3dbd13f983d86074eefff6b693c2d0ae45ae9f7c575201df0a43e6f67fdf21
4
- data.tar.gz: 1a9c3aec79e50876d43953bac3a3b8b1b35ba158edf649466e6ceba9c7a8b5da
3
+ metadata.gz: 644f7b057adc20478b49952953a8e984d0e89190728e089a3775c2313248680a
4
+ data.tar.gz: 37c9350027e3d28e24700ebb25bd449fb7aa7a1466c9c663d7681ca29e69fb8c
5
5
  SHA512:
6
- metadata.gz: 32672c88eb7fe8627b8d499d136cf5023fd3709e172731cbdb1b4fd2ca22fcdee45f36f0cf6522ab6907e085815458b422487a4afe9db22af43c6ba65e587227
7
- data.tar.gz: '09452083132409f72b7509dad2db27d834b183017900223c9678ef900e1e69259f5af444454f38084cb848c21364d717a2364bdc90e380c4972e1029d306133c'
6
+ metadata.gz: 6060f31e07e7b7d76abd36760217814f385c73dad65e8d533e503eb5cdcaa5cbfc86257ad87e820ccf57395f3d0df6c3d4fa7d9c5dc77537b0582ea217d6be2c
7
+ data.tar.gz: cfb254eefc93331ef067043c1861337886f6749871bc5cdbf44e282238e84970f5bc1eb421833920968839c91bf0f3319f39c93a970af477e4bf194cfea88b11
data/.vimproject CHANGED
@@ -5,6 +5,7 @@ scout-gear=/$PWD filter="*.rb *.yaml" {
5
5
  lib=lib {
6
6
  scout-gear.rb
7
7
  scout=scout{
8
+ misc.rb
8
9
  exceptions.rb
9
10
  meta_extension.rb
10
11
  tmpfile.rb
@@ -27,6 +28,7 @@ scout-gear=/$PWD filter="*.rb *.yaml" {
27
28
  path.rb
28
29
  path=path{
29
30
  find.rb
31
+ util.rb
30
32
  }
31
33
  }
32
34
  }
@@ -42,4 +44,3 @@ scout-gear=/$PWD filter="*.rb *.yaml" {
42
44
  }
43
45
  }
44
46
  }
45
-
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.1
1
+ 1.2.0
@@ -208,7 +208,7 @@ module Log
208
208
  done_msg << Log.color(:magenta, " · " << desc)
209
209
  print(io, Log.up_lines(@depth) << done_msg << Log.down_lines(@depth))
210
210
 
211
- FileUtils.rm file if file and File.exists?(file)
211
+ FileUtils.rm file if file and File.exist?(file)
212
212
 
213
213
  @callback.call self if @callback
214
214
  end
@@ -81,7 +81,6 @@ module Log
81
81
 
82
82
  def self.with_bar(max, options = {})
83
83
  bar = new_bar(max, options)
84
- res = nil
85
84
  begin
86
85
  error = false
87
86
  keep = false
data/lib/scout/log.rb CHANGED
@@ -35,7 +35,7 @@ module Log
35
35
  def self.last_caller(stack)
36
36
  line = nil
37
37
  pos ||= 0
38
- while line.nil? or line =~ /scout\/helper\/log\.rb/ and stack.any?
38
+ while line.nil? or line =~ /scout\/log\.rb/ and stack.any?
39
39
  line = stack.shift
40
40
  end
41
41
  line ||= caller.first
@@ -13,9 +13,23 @@ module MetaExtension
13
13
 
14
14
  meta.define_method(:setup) do |obj,*rest|
15
15
  obj.extend base
16
- self.class_variable_get("@@extension_attrs").zip(rest).each do |name,value|
16
+ attrs = self.class_variable_get("@@extension_attrs")
17
+
18
+ return if attrs.nil? || attrs.empty?
19
+
20
+ if rest.length == 1 && Hash === (rlast = rest.last) &&
21
+ ! (rlkey = rlast.keys.first).nil? &&
22
+ attrs.include?(rlkey.to_sym)
23
+
24
+ pairs = rlast
25
+ else
26
+ pairs = attrs.zip(rest)
27
+ end
28
+
29
+ pairs.each do |name,value|
17
30
  obj.instance_variable_set("@#{name}", value)
18
31
  end
32
+
19
33
  obj
20
34
  end
21
35
 
data/lib/scout/misc.rb ADDED
@@ -0,0 +1,13 @@
1
+ module Misc
2
+ def self.in_dir(dir)
3
+ old_pwd = FileUtils.pwd
4
+ begin
5
+ FileUtils.mkdir_p dir unless File.exist?(dir)
6
+ FileUtils.cd dir
7
+ yield
8
+ ensure
9
+ FileUtils.cd old_pwd
10
+ end
11
+ end
12
+
13
+ end
@@ -12,54 +12,103 @@ module Path
12
12
  end
13
13
 
14
14
  def self.follow(path, map)
15
- map.sub('{PKGDIR}', path.pkgdir).
15
+ map.sub('{PKGDIR}', path.pkgdir || Path.default_pkgdir).
16
16
  sub('{RESOURCE}', path.to_s).
17
17
  sub('{PWD}', FileUtils.pwd).
18
18
  sub('{TOPLEVEL}', path._toplevel).
19
19
  sub('{SUBPATH}', path._subpath).
20
20
  sub('{BASENAME}', File.basename(path)).
21
21
  sub('{PATH}', path).
22
- sub('{LIBDIR}', path.libdir).
22
+ sub('{LIBDIR}', path.libdir || Path.caller_lib_dir).
23
23
  sub('{REMOVE}/', '').
24
24
  sub('{REMOVE}', '').gsub(/\/+/,'/')
25
25
  end
26
26
 
27
- PATH_MAPS = IndiferentHash.setup({
28
- :current => File.join("{PWD}", "{TOPLEVEL}", "{SUBPATH}"),
29
- :user => File.join(ENV['HOME'], ".{PKGDIR}", "{TOPLEVEL}", "{SUBPATH}"),
30
- :global => File.join('/', "{TOPLEVEL}", "{PKGDIR}", "{SUBPATH}"),
31
- :usr => File.join('/usr/', "{TOPLEVEL}", "{PKGDIR}", "{SUBPATH}"),
32
- :local => File.join('/usr/local', "{TOPLEVEL}", "{PKGDIR}", "{SUBPATH}"),
33
- :fast => File.join('/fast', "{TOPLEVEL}", "{PKGDIR}", "{SUBPATH}"),
34
- :cache => File.join('/cache', "{TOPLEVEL}", "{PKGDIR}", "{SUBPATH}"),
35
- :bulk => File.join('/bulk', "{TOPLEVEL}", "{PKGDIR}", "{SUBPATH}"),
36
- :lib => File.join('{LIBDIR}', "{TOPLEVEL}", "{SUBPATH}"),
37
- :base => File.join(Path.caller_lib_dir(__FILE__), "{TOPLEVEL}", "{SUBPATH}"),
38
- :default => :user
39
- })
40
-
41
- MAP_SEARCH = %w(current workflow user local global lib fast cache bulk)
42
-
43
- def _follow(map_name)
44
- map = PATH_MAPS[map_name]
27
+ def self.path_maps
28
+ @@path_maps ||= IndiferentHash.setup({
29
+ :current => File.join("{PWD}", "{TOPLEVEL}", "{SUBPATH}"),
30
+ :user => File.join(ENV['HOME'], ".{PKGDIR}", "{TOPLEVEL}", "{SUBPATH}"),
31
+ :global => File.join('/', "{TOPLEVEL}", "{PKGDIR}", "{SUBPATH}"),
32
+ :usr => File.join('/usr/', "{TOPLEVEL}", "{PKGDIR}", "{SUBPATH}"),
33
+ :local => File.join('/usr/local', "{TOPLEVEL}", "{PKGDIR}", "{SUBPATH}"),
34
+ :fast => File.join('/fast', "{TOPLEVEL}", "{PKGDIR}", "{SUBPATH}"),
35
+ :cache => File.join('/cache', "{TOPLEVEL}", "{PKGDIR}", "{SUBPATH}"),
36
+ :bulk => File.join('/bulk', "{TOPLEVEL}", "{PKGDIR}", "{SUBPATH}"),
37
+ :lib => File.join('{LIBDIR}', "{TOPLEVEL}", "{SUBPATH}"),
38
+ :base => File.join(Path.caller_lib_dir(__FILE__), "{TOPLEVEL}", "{SUBPATH}"),
39
+ :default => :user
40
+ })
41
+ end
42
+
43
+ def self.map_search
44
+ @@map_search ||= %w(current workflow user local global lib fast cache bulk)
45
+ end
46
+
47
+ def self.search_order
48
+ @@search_order ||= (path_maps.keys & map_search) + (path_maps.keys - map_search)
49
+ end
50
+
51
+ SLASH = "/"[0]
52
+ DOT = "."[0]
53
+ def located?
54
+ # OPEN RESOURCE
55
+ self.slice(0,1) == SLASH || (self.char(0,1) == DOT && self.char(1,2) == SLASH) # || (resource != Rbbt && (Open.remote?(self) || Open.ssh?(self)))
56
+ end
57
+
58
+ def annotate_found_where(found, where)
59
+ self.annotate(found).tap{|p|
60
+ p.instance_variable_set("@where", where)
61
+ p.instance_variable_set("@original", self.dup)
62
+ }
63
+ end
64
+
65
+ def where
66
+ @where
67
+ end
68
+
69
+ def original
70
+ @original
71
+ end
72
+
73
+ def follow(map_name = :default, annotate = true)
74
+ map = Path.path_maps[map_name]
45
75
  while Symbol === map
46
- map = PATH_MAPS[map]
76
+ map_name = map
77
+ map = Path.path_maps[map_name]
47
78
  end
48
- Path.follow(self, map)
79
+ found = Path.follow(self, map)
80
+
81
+ annotate_found_where(found, map_name) if annotate
82
+
83
+ found
49
84
  end
50
85
 
51
86
  def find(where = nil)
52
- return _follow(where) if where
87
+ return self if located?
88
+ return follow(where) if where
89
+
53
90
 
54
- all_maps = PATH_MAPS.keys
55
- search_order = MAP_SEARCH & all_maps + (all_maps - MAP_SEARCH)
91
+ Path.search_order.each do |map_name|
92
+ found = follow(map_name, false)
56
93
 
57
- search_order.each do |name|
58
- map = PATH_MAPS[name]
59
- real_path = _follow(map)
60
- return real_path if File.exists?(real_path)
94
+ return annotate_found_where(found, map_name) if File.exist?(found) || File.directory?(real_path)
61
95
  end
62
96
 
63
- return _follow(:default)
97
+ return follow(:default)
64
98
  end
99
+
100
+ def exist?
101
+ # OPEN
102
+ found = self.find
103
+ File.exist?(found) || File.directory?(found)
104
+ end
105
+
106
+ alias exists? exist?
107
+
108
+ def find_all(caller_lib = nil, search_paths = nil)
109
+ Path.search_order
110
+ .collect{|where| find(where) }
111
+ .select{|file| file.exist? }.uniq
112
+ end
113
+
65
114
  end
@@ -0,0 +1,52 @@
1
+ module Path
2
+ def directory?
3
+ return nil unless self.exist?
4
+ File.directory?(self.find)
5
+ end
6
+
7
+ def dirname
8
+ self.annotate(File.dirname(self))
9
+ end
10
+
11
+ def basename
12
+ self.annotate(File.basename(self))
13
+ end
14
+
15
+
16
+ def glob(pattern = '*')
17
+ if self.include? "*"
18
+ self.glob_all
19
+ else
20
+ return [] unless self.exist?
21
+ found = self.find
22
+ exp = File.join(found, pattern)
23
+ paths = Dir.glob(exp).collect{|f| self.annotate(f) }
24
+
25
+ paths.each do |p|
26
+ p.original = File.join(found.original, p.sub(/^#{found}/, ''))
27
+ end if found.original
28
+
29
+ paths
30
+ end
31
+ end
32
+
33
+ def glob_all(pattern = nil, caller_lib = nil, search_paths = nil)
34
+ search_paths ||= Path.search_paths
35
+ search_paths = search_paths.dup
36
+
37
+ location_paths = {}
38
+ search_paths.keys.collect do |where|
39
+ found = find(where, Path.caller_lib_dir, search_paths)
40
+ paths = pattern ? Dir.glob(File.join(found, pattern)) : Dir.glob(found)
41
+
42
+ paths = paths.collect{|p| self.annotate p }
43
+
44
+ paths = paths.each do |p|
45
+ p.original = File.join(found.original, p.sub(/^#{found}/, ''))
46
+ p.where = where
47
+ end if found.original and pattern
48
+
49
+ location_paths[where] = paths
50
+ end
51
+ end
52
+ end
data/lib/scout/path.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  require_relative 'meta_extension'
2
+ require_relative 'path/find'
3
+ require_relative 'path/util'
2
4
 
3
5
  module Path
4
6
  extend MetaExtension
@@ -31,11 +33,16 @@ module Path
31
33
  return nil
32
34
  end
33
35
 
34
- def self.setup(path, pkgdir = 'scout', libdir = nil)
35
- path.extend Path
36
- path.pkgdir = pkgdir
37
- path.libdir = libdir || Path.caller_lib_dir
38
- path
36
+ def self.default_pkgdir
37
+ @@default_pkgdir = 'scout'
38
+ end
39
+
40
+ def pkgdir
41
+ @pkgdir ||= Path.default_pkgdir
42
+ end
43
+
44
+ def libdir
45
+ @libdir ||= Path.caller_lib_dir
39
46
  end
40
47
 
41
48
  def join(subpath, prevpath = nil)
data/lib/scout/tmpfile.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'fileutils'
2
+ require_relative 'misc'
2
3
 
3
4
  module TmpFile
4
5
  def self.user_tmp(subdir = nil)
@@ -83,13 +84,8 @@ module TmpFile
83
84
 
84
85
  def self.in_dir(*args)
85
86
  with_dir(*args) do |dir|
86
- old_pwd = FileUtils.pwd
87
- begin
88
- FileUtils.mkdir_p dir unless File.exist?(dir)
89
- FileUtils.cd dir
87
+ Misc.in_dir dir do
90
88
  yield dir
91
- ensure
92
- FileUtils.cd old_pwd
93
89
  end
94
90
  end
95
91
  end
data/lib/scout-gear.rb CHANGED
@@ -1,3 +1,4 @@
1
1
  require_relative 'scout/indiferent_hash'
2
2
  require_relative 'scout/tmpfile'
3
3
  require_relative 'scout/log'
4
+ require_relative 'scout/path'
data/scout-gear.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: scout-gear 1.1.1 ruby lib
5
+ # stub: scout-gear 1.2.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "scout-gear".freeze
9
- s.version = "1.1.1"
9
+ s.version = "1.2.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
@@ -40,16 +40,20 @@ Gem::Specification.new do |s|
40
40
  "lib/scout/log/progress/report.rb",
41
41
  "lib/scout/log/progress/util.rb",
42
42
  "lib/scout/meta_extension.rb",
43
+ "lib/scout/misc.rb",
43
44
  "lib/scout/path.rb",
44
45
  "lib/scout/path/find.rb",
46
+ "lib/scout/path/util.rb",
45
47
  "lib/scout/tmpfile.rb",
46
48
  "scout-gear.gemspec",
47
49
  "test/scout/indiferent_hash/test_options.rb",
48
50
  "test/scout/log/test_progress.rb",
49
51
  "test/scout/path/test_find.rb",
52
+ "test/scout/path/test_util.rb",
50
53
  "test/scout/test_indiferent_hash.rb",
51
54
  "test/scout/test_log.rb",
52
55
  "test/scout/test_meta_extension.rb",
56
+ "test/scout/test_misc.rb",
53
57
  "test/scout/test_path.rb",
54
58
  "test/scout/test_tmpfile.rb",
55
59
  "test/test_helper.rb"
@@ -1,6 +1,8 @@
1
1
  require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
2
  require 'scout/path'
3
+ require 'scout/misc'
3
4
  require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
5
+
4
6
  class TestPathFind < Test::Unit::TestCase
5
7
  def test_parts
6
8
  path = Path.setup("share/data/some_file", 'scout')
@@ -30,5 +32,36 @@ class TestPathFind < Test::Unit::TestCase
30
32
  assert_equal File.join(tmpdir,"share/data/some_file"), path.find(:current)
31
33
  end
32
34
  end
35
+
36
+ def test_current_find
37
+ path = Path.setup("share/data/some_file", 'scout')
38
+ TmpFile.in_dir do |tmpdir|
39
+ FileUtils.mkdir_p(File.dirname(File.join(tmpdir, path)))
40
+ File.write(File.join(tmpdir, path), 'string')
41
+ assert_equal File.join(tmpdir,"share/data/some_file"), path.find
42
+ assert_equal :current, path.find.where
43
+ assert_equal "share/data/some_file", path.find.original
44
+ end
45
+ end
46
+
47
+ def test_current_find_all
48
+ path = Path.setup("share/data/some_file", 'scout')
49
+ TmpFile.with_dir do |tmpdir|
50
+ Path.setup tmpdir
51
+
52
+ FileUtils.mkdir_p(tmpdir.lib)
53
+ FileUtils.mkdir_p(tmpdir.share.data)
54
+ File.write(tmpdir.share.data.some_file, 'string')
55
+
56
+ FileUtils.mkdir_p(tmpdir.subdir.share.data)
57
+ File.write(tmpdir.subdir.share.data.some_file, 'string')
58
+
59
+ path.libdir = tmpdir
60
+ Misc.in_dir tmpdir.subdir do
61
+ assert_equal 2, path.find_all.length
62
+ end
63
+ end
64
+ end
65
+
33
66
  end
34
67
 
@@ -0,0 +1,22 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require 'scout/path'
3
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
4
+
5
+ class TestPathUtil < Test::Unit::TestCase
6
+ def test_dirname
7
+ p = Path.setup("/usr/share/scout/data")
8
+
9
+ assert_equal "/usr/share/scout", p.dirname
10
+ end
11
+
12
+ def test_glob
13
+ TmpFile.in_dir :erase => false do |tmpdir|
14
+ Path.setup tmpdir
15
+ File.write(tmpdir.foo, 'foo')
16
+ File.write(tmpdir.bar, 'bar')
17
+ assert_equal 2, tmpdir.glob.length
18
+ assert_equal %w(foo bar).sort, tmpdir.glob.collect{|p| p.basename }.sort
19
+ end
20
+ end
21
+ end
22
+
@@ -5,10 +5,10 @@ class TestMetaExtension < Test::Unit::TestCase
5
5
  module ExtensionClass
6
6
  extend MetaExtension
7
7
 
8
- extension_attr :code
8
+ extension_attr :code, :code2
9
9
  end
10
10
 
11
- def test_setup
11
+ def test_setup_annotate
12
12
  str = "String"
13
13
  ExtensionClass.setup(str, :code)
14
14
  assert ExtensionClass === str
@@ -18,5 +18,19 @@ class TestMetaExtension < Test::Unit::TestCase
18
18
  str.annotate(str2)
19
19
  assert_equal :code, str2.code
20
20
  end
21
+
22
+ def test_setup_alternatives
23
+ str = "String"
24
+
25
+ ExtensionClass.setup(str, :code2 => :code)
26
+ assert_equal :code, str.code2
27
+
28
+ ExtensionClass.setup(str, code2: :code)
29
+ assert_equal :code, str.code2
30
+
31
+ ExtensionClass.setup(str, "code2" => :code)
32
+ assert_equal :code, str.code2
33
+
34
+ end
21
35
  end
22
36
 
@@ -0,0 +1,13 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+
4
+ class TestMisc < Test::Unit::TestCase
5
+ def test_in_dir
6
+ TmpFile.with_file do |tmpdir|
7
+ Misc.in_dir tmpdir do
8
+ assert_equal tmpdir, FileUtils.pwd
9
+ end
10
+ end
11
+ end
12
+ end
13
+
@@ -32,5 +32,21 @@ class TestPath < Test::Unit::TestCase
32
32
  assert_equal 'scout', path.pkgdir
33
33
  assert path.libdir.end_with?("scout-gear")
34
34
  end
35
+
36
+ def test_lib_dir
37
+ TmpFile.with_file do |tmpdir|
38
+ Path.setup tmpdir
39
+ FileUtils.mkdir_p tmpdir.lib
40
+ File.write tmpdir.lib.file, <<-EOR
41
+ require '#{File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')}'
42
+ a = "1"
43
+ Path.setup(a)
44
+ print a.libdir
45
+ EOR
46
+ Misc.in_dir tmpdir.tmp do
47
+ assert_equal tmpdir, `ruby #{tmpdir.lib.file}`
48
+ end
49
+ end
50
+ end
35
51
  end
36
52
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scout-gear
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Vazquez
@@ -109,16 +109,20 @@ files:
109
109
  - lib/scout/log/progress/report.rb
110
110
  - lib/scout/log/progress/util.rb
111
111
  - lib/scout/meta_extension.rb
112
+ - lib/scout/misc.rb
112
113
  - lib/scout/path.rb
113
114
  - lib/scout/path/find.rb
115
+ - lib/scout/path/util.rb
114
116
  - lib/scout/tmpfile.rb
115
117
  - scout-gear.gemspec
116
118
  - test/scout/indiferent_hash/test_options.rb
117
119
  - test/scout/log/test_progress.rb
118
120
  - test/scout/path/test_find.rb
121
+ - test/scout/path/test_util.rb
119
122
  - test/scout/test_indiferent_hash.rb
120
123
  - test/scout/test_log.rb
121
124
  - test/scout/test_meta_extension.rb
125
+ - test/scout/test_misc.rb
122
126
  - test/scout/test_path.rb
123
127
  - test/scout/test_tmpfile.rb
124
128
  - test/test_helper.rb