dire 0.1.1 → 0.1.3

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: 4ce56a38011061077ffc3a256d72050176ab80382ecaf6ac3febfac060cee877
4
- data.tar.gz: e19678d4c894844c7f46df26aa89bce0bf7629160ba86a636f569183afbcd9db
3
+ metadata.gz: be6f93fb0a1456e69128bc968babaad69ac2a126985441470660d3e6467b383c
4
+ data.tar.gz: 560ead570a52d7fa967c7b54290b17875fc0d7568d95178547c6b787d0a534c8
5
5
  SHA512:
6
- metadata.gz: df15ddb2eb3edf5f31865a338672ba4e1a710224920cfe4dab1f51d125cd459da816a09cef3dab076af8ca51c47ae59c4cba96a5d6ab05a0f419eb33d2306fb6
7
- data.tar.gz: 378045dc2b030912a0b5bf1ae42771c5e46786cf09614aaffc8b53ff62a8aca7e91a893b5b6a6ebc267d5542e07f063f3d6bf6a1bef2894723654f881b8818c5
6
+ metadata.gz: 2c76d776150fdb1411c97a4b36eff6aa037cf2c19271c1e8784a52dfea5a0c7e7c2b12f4fd616ab76bde04f97c407d1c55ecc13ba57e8f987cad2331a2987bd3
7
+ data.tar.gz: 8708281c65f24db613e9de7663b705fcd9022a048fe7a306529a4f1e512f470a5d5c34058fe8262d11842dfd3bfa8366a385c0ccd8434cc623aca830f14364ae
data/lib/dire/dir.rb CHANGED
@@ -1,12 +1,12 @@
1
1
  module Dire
2
2
  class Dir < Node
3
- @@invalid_link_handler = -> (nodes, path) {}
3
+ @@invalid_link_handler = -> (root, nodes, path) {}
4
4
 
5
5
  def self.invalid_link_handler= lambda
6
6
  @@invalid_link_handler = lambda
7
7
  end
8
8
 
9
- @@invalid_path_handler = -> (nodes, path) {}
9
+ @@invalid_path_handler = -> (root, nodes, path) {}
10
10
 
11
11
  def self.invalid_path_handler= lambda
12
12
  @@invalid_path_handler = lambda
@@ -38,16 +38,16 @@ module Dire
38
38
  return @nodes if @nodes
39
39
 
40
40
  @nodes = absolute_path.glob '*', ::File::FNM_DOTMATCH
41
- @nodes = @nodes.each_with_object(Array.new) do |node, nodes|
42
- next if ignore? node
41
+ @nodes = @nodes.each_with_object(Array.new) do |path, nodes|
42
+ next if ignore? path
43
43
 
44
- if absolute_path.to_s < node.to_s
44
+ if absolute_path.to_s < path.to_s
45
45
  begin
46
- nodes.push get(node)
46
+ nodes.push get(path)
47
47
  rescue Dire::Error::InvalidLink
48
- @@invalid_link_handler.(nodes, node)
48
+ @@invalid_link_handler.(root, nodes, path)
49
49
  rescue Dire::Error::InvalidPath
50
- @@invalid_path_handler.(nodes, node)
50
+ @@invalid_path_handler.(root, nodes, path)
51
51
  end
52
52
  end
53
53
  end
data/lib/dire/file.rb CHANGED
@@ -5,7 +5,7 @@ module Dire
5
5
  def binary?
6
6
  return @binary if @binary
7
7
 
8
- unless %w(application text).include? mime.mediatype
8
+ if mime && !['application', 'text'].include?(mime.mediatype)
9
9
  return @binary = true
10
10
  end
11
11
 
@@ -0,0 +1,21 @@
1
+ module Dire::Module::Check
2
+ def == other
3
+ path.to_s == other.path.to_s
4
+ end
5
+
6
+ def broken?
7
+ false
8
+ end
9
+
10
+ def known?
11
+ true
12
+ end
13
+
14
+ def parent? node
15
+ parent == node
16
+ end
17
+
18
+ def root?
19
+ false
20
+ end
21
+ end
@@ -0,0 +1,37 @@
1
+ module Dire::Module::Path
2
+ def absolute_path
3
+ path
4
+ end
5
+
6
+ def name
7
+ absolute_path.basename.to_s
8
+ end
9
+
10
+ def param
11
+ relative_path.to_s
12
+ end
13
+
14
+ def relative_path
15
+ chop path
16
+ end
17
+
18
+ private
19
+
20
+ def chop pth
21
+ expand(pth).relative_path_from(root)
22
+ end
23
+
24
+ def expand pth
25
+ path.join(pth).expand_path
26
+ end
27
+
28
+ def ignore? path
29
+ Dire::IGNORE.any? do |ignore|
30
+ File.fnmatch? ignore, path, File::FNM_DOTMATCH | File::FNM_PATHNAME
31
+ end
32
+ end
33
+
34
+ def inside? path
35
+ expand(path).to_s.index(root.to_s) == 0
36
+ end
37
+ end
@@ -0,0 +1,29 @@
1
+ module Dire::Module::Validity
2
+ def validate!
3
+ begin
4
+ if ignore? path
5
+ raise Errno::ENOENT if ignore? path
6
+ end
7
+
8
+ path.lstat
9
+ rescue Errno::ENOENT
10
+ raise Dire::Error::InvalidPath, 'Not found'
11
+ end
12
+
13
+ unless inside? path
14
+ raise Dire::Error::InvalidPath, 'Outside root'
15
+ end
16
+
17
+ true
18
+ end
19
+
20
+ private
21
+
22
+ def validate_type! name
23
+ unless type == name
24
+ raise Dire::Error::InvalidPath, 'Node missmatch'
25
+ end
26
+
27
+ true
28
+ end
29
+ end
data/lib/dire/node.rb CHANGED
@@ -1,18 +1,17 @@
1
1
  module Dire
2
2
  class Node
3
- include Mixin::Check
4
- include Mixin::Path
3
+ include Module::Check, Module::Path, Module::Validity
5
4
 
6
5
  attr_reader :path, :root
7
6
 
8
- def initialize node, root, validate = true
7
+ def initialize node, root, validate: true
9
8
  @path = str2abs node
10
9
  @root = plant root
11
10
 
12
11
  validate! if validate
13
12
  end
14
13
 
15
- def get path, validate = true
14
+ def get path, validate: true
16
15
  path = expand path
17
16
  type = path.ftype rescue nil
18
17
 
@@ -24,12 +23,12 @@ module Dire
24
23
  else Other
25
24
  end
26
25
 
27
- const.new path, root, validate
26
+ const.new path, root, validate: validate
28
27
  end
29
28
 
30
29
  def parent
31
30
  Dire::Dir.new absolute_path.join('..'), root
32
- rescue Error::InvalidPath
31
+ rescue Dire::Error::InvalidPath
33
32
  nil
34
33
  end
35
34
 
data/lib/dire/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dire
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.3'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dire
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Filip Pyda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-26 00:00:00.000000000 Z
11
+ date: 2021-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mimemagic
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 2.4.2
33
+ version: 2.5.1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 2.4.2
40
+ version: 2.5.1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -71,8 +71,9 @@ files:
71
71
  - lib/dire/error/invalid_root.rb
72
72
  - lib/dire/file.rb
73
73
  - lib/dire/link.rb
74
- - lib/dire/mixin/check.rb
75
- - lib/dire/mixin/path.rb
74
+ - lib/dire/module/check.rb
75
+ - lib/dire/module/path.rb
76
+ - lib/dire/module/validity.rb
76
77
  - lib/dire/node.rb
77
78
  - lib/dire/other.rb
78
79
  - lib/dire/version.rb
@@ -1,57 +0,0 @@
1
- module Dire::Mixin::Check
2
- def == other
3
- path.to_s == other.path.to_s
4
- end
5
-
6
- def broken?
7
- false
8
- end
9
-
10
- def known?
11
- true
12
- end
13
-
14
- def parent? node
15
- parent == node
16
- end
17
-
18
- def root?
19
- false
20
- end
21
-
22
- def validate!
23
- begin
24
- raise Errno::ENOENT if ignore? path
25
-
26
- path.lstat
27
- rescue Errno::ENOENT
28
- raise Dire::Error::InvalidPath, 'Not found'
29
- end
30
-
31
- unless inside? path
32
- raise Dire::Error::InvalidPath, 'Outside root'
33
- end
34
-
35
- true
36
- end
37
-
38
- private
39
-
40
- def ignore? path
41
- Dire::IGNORE.any? do |ignore|
42
- File.fnmatch? ignore, path, File::FNM_PATHNAME
43
- end
44
- end
45
-
46
- def inside? path
47
- expand(path).to_s.index(root.to_s) == 0
48
- end
49
-
50
- def validate_type! name
51
- unless type == name
52
- raise Dire::Error::InvalidPath, 'Node missmatch'
53
- end
54
-
55
- true
56
- end
57
- end
@@ -1,23 +0,0 @@
1
- module Dire::Mixin::Path
2
- def absolute_path
3
- path
4
- end
5
-
6
- def param
7
- relative_path.to_s
8
- end
9
-
10
- def relative_path
11
- chop path
12
- end
13
-
14
- private
15
-
16
- def chop pth
17
- expand(pth).relative_path_from(root)
18
- end
19
-
20
- def expand pth
21
- path.join(pth).expand_path
22
- end
23
- end