hiiro 0.1.129 → 0.1.130

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
  SHA256:
3
- metadata.gz: b9fef3df8af777d1973ef079667864c844647863d4d4e2f4a25936f7ec6e4398
4
- data.tar.gz: 93d49ce15ec7ed31e42101d77bc88f8fa6d526d33d370cb5d49d7752186acac8
3
+ metadata.gz: 9ee15221ef5fd0d6dd334387e083049fc53cec41df755c270451f1329e63804a
4
+ data.tar.gz: 89df78fc18b86391dced6ec9e7f1dbb597f6f6549a3c627cc5b2898c2dd23b94
5
5
  SHA512:
6
- metadata.gz: 60896c6b8783fd7b93d4c3a7fe8e82216cc03d6154cce5f4288867661accbae76b596e1833bb8d6141216aa72880a7f1def2dae2d2a69505e2fb5d2688224951
7
- data.tar.gz: 530165f760d2e81f6bfa88eac2b9848e067484a02b05ee09876a79db06fe7714721925c2c2bc8f553e9748da8728b94ee5f11f690c75e2cde79e820effc0e3e3
6
+ metadata.gz: 6e043a980f853c53b429500047fc872092e21488a45ad9bfd1cdf64b4fab56d1513423cfe7af061988c468cb10272935cca9ceadad059d972c03c1ba51c152d0
7
+ data.tar.gz: 3abc9a1acfd9ff38060b6d8c01accae3efa5cea58113b8f0b1378b1270054b0e95543797400b9c89a5ed941c40679ab51299b447e86ccdf676189f561fb8dae6
data/bin/h-misc CHANGED
@@ -9,24 +9,19 @@ Hiiro.run {
9
9
  end
10
10
 
11
11
  pwd = Hiiro::Paths.new(Dir.pwd)
12
- outside_basedir = opts.args.inject({}) do |basedir,h|
13
- real_base = pwd.child(basedir)
14
- symlinks = pwd.symlinks_in(real_base)
12
+ outside_basedir = opts.args.inject({}) do |h,basedir|
13
+ symlinks = pwd.symlinks_in(basedir)
15
14
 
16
- mapping = symlinks.each_with_object({}) do |link,h|
17
- h[link] = pwd.symlink_dest(link)
18
- end
19
-
20
- outside = mapping.select{|link,dest|
21
- pwd.outside_dir?(dest, real_base)
22
- }
23
-
24
- outside.each do |link,dest|
25
- puts
26
- puts "LINK: #{link}"
27
- puts "DEST: #{dest}"
28
- puts "is outside => #{real_base}"
29
- end
15
+ outside_dir = symlinks
16
+ .reject{|l| l.dest_in_dir?(basedir) }
17
+ .tap do |outside|
18
+ outside.each do |link,dest|
19
+ puts
20
+ puts "LINK: #{link}"
21
+ puts "DEST: #{dest}"
22
+ puts "is outside => #{real_base}"
23
+ end
24
+ end
30
25
  end
31
26
  end
32
27
  }
data/lib/hiiro/paths.rb CHANGED
@@ -1,37 +1,44 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "hiiro"
4
+ require "delegate"
4
5
 
5
6
  class Hiiro
6
7
  class Paths
7
8
  attr_reader :base
8
9
 
9
- def initialize(base)
10
+ def initialize(base=Dir.pwd)
10
11
  @base = Pathname.new base
11
12
  end
12
13
 
13
- def child(path)
14
- if File.absolute_path?(path)
15
- Pathname.new(path)
16
- else
17
- base.join path
18
- end
14
+ def from_base(file)
15
+ path = Pathname.new(file)
16
+ path.relative_path_from(base)
19
17
  end
20
18
 
21
19
  def symlinks_in(path)
22
- subdir = child(path)
20
+ subdir = Pathname.new(path)
23
21
 
24
- subdir.find.select(&:symlink?)
22
+ subdir.find
23
+ .select(&:symlink?)
24
+ .map { |link| Symlink.new(link) }
25
25
  end
26
26
 
27
- def symlink_dest(link)
28
- link.readlink.expand_path(link.dirname)
29
- end
27
+ class Symlink < SimpleDelegator
28
+ def path
29
+ @path ||= Pathname.new(__getobj__)
30
+ end
30
31
 
31
- def outside_dir?(file, dir)
32
- relative_path = file.relative_path_from(dir)
32
+ def dest
33
+ path.readlink
34
+ end
35
+
36
+ def dest_in_dir?(dir)
37
+ dir = Pathname.new(dir)
33
38
 
34
- relative_path.descend.first == Pathname.new('..')
39
+ relpath = dest.relative_path_from(dir)
40
+ relpath.descend.first.to_s != '..'
41
+ end
35
42
  end
36
43
  end
37
44
  end
data/lib/hiiro/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Hiiro
2
- VERSION = "0.1.129"
2
+ VERSION = "0.1.130"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hiiro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.129
4
+ version: 0.1.130
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Toyota