faster_path 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Cargo.lock +7 -7
- data/Cargo.toml +1 -1
- data/faster_path.gemspec +1 -2
- data/lib/faster_path.rb +32 -84
- data/lib/faster_path/asset_resolution.rb +3 -2
- data/lib/faster_path/optional/monkeypatches.rb +6 -8
- data/lib/faster_path/optional/refinements.rb +6 -8
- data/lib/faster_path/platform.rb +60 -0
- data/lib/faster_path/version.rb +1 -1
- data/src/helpers.rs +10 -6
- data/src/lib.rs +19 -21
- data/src/pathname.rs +69 -49
- metadata +6 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 95885428dc6e619ea1069fd3473cd68ffd762eca29d09f1185ebfafc7cbcbebf
|
4
|
+
data.tar.gz: 4ad3a157841d4003e7314295fb955a01565c903c05942b112527a95818664f7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 881379d959fcadeaf9e23236327b9b2da8315a3e95307718cc4ff763002eb1ea11134b7607518f98a6b20a9d5b9db3b38d31174d85b8c5bbc3fdca6a3f8c8aac
|
7
|
+
data.tar.gz: 961dd0da7cff5e3ac96aa3745dfe803464d748784fabe51a49988afb254e6995d168e640abc25b7cae64379b1c1b53b6faa5f299ee74adcc2d01ad11cf05153a
|
data/Cargo.lock
CHANGED
@@ -10,7 +10,7 @@ dependencies = [
|
|
10
10
|
"array_tool 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
11
11
|
"lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
12
12
|
"memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
13
|
-
"ruru 0.9.3 (
|
13
|
+
"ruru 0.9.3 (git+https://github.com/danielpclark/ruru?branch=playground)",
|
14
14
|
]
|
15
15
|
|
16
16
|
[[package]]
|
@@ -38,8 +38,8 @@ dependencies = [
|
|
38
38
|
|
39
39
|
[[package]]
|
40
40
|
name = "ruby-sys"
|
41
|
-
version = "0.
|
42
|
-
source = "
|
41
|
+
version = "0.3.0"
|
42
|
+
source = "git+https://github.com/danielpclark/ruby-sys?branch=playground#08c96179e46ce8a5fec25e1b4aeb5d9c63a2245e"
|
43
43
|
dependencies = [
|
44
44
|
"libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)",
|
45
45
|
]
|
@@ -47,10 +47,10 @@ dependencies = [
|
|
47
47
|
[[package]]
|
48
48
|
name = "ruru"
|
49
49
|
version = "0.9.3"
|
50
|
-
source = "
|
50
|
+
source = "git+https://github.com/danielpclark/ruru?branch=playground#aa4a08c48374bb13983cf6de5df7125a18ea1169"
|
51
51
|
dependencies = [
|
52
52
|
"lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
53
|
-
"ruby-sys 0.
|
53
|
+
"ruby-sys 0.3.0 (git+https://github.com/danielpclark/ruby-sys?branch=playground)",
|
54
54
|
]
|
55
55
|
|
56
56
|
[metadata]
|
@@ -59,5 +59,5 @@ dependencies = [
|
|
59
59
|
"checksum lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c8f31047daa365f19be14b47c29df4f7c3b581832407daabe6ae77397619237d"
|
60
60
|
"checksum libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)" = "2370ca07ec338939e356443dac2296f581453c35fe1e3a3ed06023c49435f915"
|
61
61
|
"checksum memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "796fba70e76612589ed2ce7f45282f5af869e0fdd7cc6199fa1aa1f1d591ba9d"
|
62
|
-
"checksum ruby-sys 0.
|
63
|
-
"checksum ruru 0.9.3 (
|
62
|
+
"checksum ruby-sys 0.3.0 (git+https://github.com/danielpclark/ruby-sys?branch=playground)" = "<none>"
|
63
|
+
"checksum ruru 0.9.3 (git+https://github.com/danielpclark/ruru?branch=playground)" = "<none>"
|
data/Cargo.toml
CHANGED
data/faster_path.gemspec
CHANGED
@@ -26,13 +26,12 @@ Gem::Specification.new do |spec|
|
|
26
26
|
|
27
27
|
spec.add_dependency "bundler", "~> 1.12"
|
28
28
|
spec.add_dependency "rake", "~> 12.0"
|
29
|
-
spec.add_dependency "ffi", "~> 1.9"
|
30
29
|
spec.add_development_dependency "read_source", "~> 0.2.6"
|
31
30
|
spec.add_development_dependency "minitest", "~> 5.10"
|
32
31
|
spec.add_development_dependency "minitest-reporters", "~> 1.1"
|
33
32
|
spec.add_development_dependency "color_pound_spec_reporter", "~> 0.0.9"
|
34
33
|
spec.add_development_dependency "rubocop", "~> 0.51"
|
35
|
-
spec.add_development_dependency "stop_watch", "~> 1.0
|
34
|
+
spec.add_development_dependency "stop_watch", "~> 1.0"
|
36
35
|
if !ENV['CI'] && ENV['GRAPH']
|
37
36
|
spec.add_development_dependency "gruff", "~> 0.7.0"
|
38
37
|
end
|
data/lib/faster_path.rb
CHANGED
@@ -1,55 +1,24 @@
|
|
1
1
|
require "faster_path/version"
|
2
2
|
require 'pathname'
|
3
|
-
require
|
3
|
+
require 'faster_path/platform'
|
4
4
|
require 'faster_path/asset_resolution'
|
5
|
+
require 'fiddle'
|
6
|
+
require 'fiddle/import'
|
5
7
|
|
6
8
|
module FasterPath
|
7
|
-
FFI_LIBRARY =
|
8
|
-
|
9
|
-
"#{File.expand_path("../target/release/", __dir__)}/#{prefix}faster_path.#{FFI::Platform::LIBSUFFIX}"
|
10
|
-
end
|
11
|
-
require 'fiddle'
|
12
|
-
library = Fiddle.dlopen(FFI_LIBRARY)
|
9
|
+
FFI_LIBRARY = FasterPath::Platform.ffi_library()
|
10
|
+
|
13
11
|
Fiddle::Function.
|
14
|
-
new(
|
12
|
+
new(Fiddle.dlopen(FFI_LIBRARY)['Init_faster_pathname'], [], Fiddle::TYPE_VOIDP).
|
15
13
|
call
|
16
14
|
|
17
|
-
|
18
|
-
private_class_method :absolute?
|
19
|
-
private_class_method :add_trailing_separator
|
15
|
+
Public.class_eval do
|
20
16
|
private_class_method :basename
|
21
|
-
private_class_method :children
|
22
|
-
private_class_method :children_compat
|
17
|
+
private_class_method :children
|
18
|
+
private_class_method :children_compat
|
23
19
|
private_class_method :chop_basename
|
24
|
-
private_class_method :
|
25
|
-
private_class_method :
|
26
|
-
private_class_method :dirname
|
27
|
-
private_class_method :entries # String results
|
28
|
-
private_class_method :entries_compat # wrap Pathname on each
|
29
|
-
private_class_method :extname
|
30
|
-
private_class_method :has_trailing_separator?
|
31
|
-
private_class_method :plus
|
32
|
-
private_class_method :relative?
|
33
|
-
end
|
34
|
-
|
35
|
-
FasterPathname.class_eval do
|
36
|
-
def initialize(arg)
|
37
|
-
unless arg.is_a? String
|
38
|
-
arg = arg.to_s
|
39
|
-
end
|
40
|
-
raise(ArgumentError, "null byte found") if arg.include?("\0")
|
41
|
-
@path = arg
|
42
|
-
end
|
43
|
-
|
44
|
-
# BAD; exposes private methods
|
45
|
-
# Need to reprivatize specific methods
|
46
|
-
def method_missing(method_name, *a, &b)
|
47
|
-
Public.send(method_name, @path, *a, &b)
|
48
|
-
end
|
49
|
-
|
50
|
-
def respond_to?(method_name, include_private = false)
|
51
|
-
Public.send(:respond_to?, method_name) || super
|
52
|
-
end
|
20
|
+
private_class_method :entries
|
21
|
+
private_class_method :entries_compat
|
53
22
|
end
|
54
23
|
|
55
24
|
def self.rust_arch_bits
|
@@ -60,68 +29,47 @@ module FasterPath
|
|
60
29
|
1.size * 8
|
61
30
|
end
|
62
31
|
|
63
|
-
def self.absolute?(pth)
|
64
|
-
FasterPathname::Public.send(:absolute?, pth)
|
65
|
-
end
|
66
|
-
|
67
|
-
def self.add_trailing_separator(pth)
|
68
|
-
FasterPathname::Public.send(:add_trailing_separator, pth)
|
69
|
-
end
|
70
|
-
|
71
32
|
def self.blank?(str)
|
72
33
|
"#{str}".strip.empty?
|
73
34
|
end
|
74
35
|
|
75
36
|
def self.basename(pth, ext="")
|
76
|
-
|
37
|
+
Public.send(:basename, pth, ext)
|
77
38
|
end
|
78
39
|
|
79
40
|
def self.children(pth, with_directory=true)
|
80
|
-
|
41
|
+
result = Public.send(:children, pth, with_directory)
|
42
|
+
return result if result
|
43
|
+
raise Errno::NOENT, "No such file or directory @ dir_initialize - #{pth}"
|
81
44
|
end
|
82
45
|
|
83
|
-
def self.
|
84
|
-
result =
|
85
|
-
result
|
46
|
+
def self.children_compat(pth, with_directory=true)
|
47
|
+
result = Public.send(:children_compat, pth, with_directory)
|
48
|
+
return result if result
|
49
|
+
raise Errno::NOENT, "No such file or directory @ dir_initialize - #{pth}"
|
86
50
|
end
|
87
51
|
|
88
|
-
def self.
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
def self.directory?(pth)
|
93
|
-
FasterPathname::Public.send(:directory?, pth)
|
94
|
-
end
|
95
|
-
|
96
|
-
def self.dirname(pth)
|
97
|
-
FasterPathname::Public.send(:dirname, pth)
|
52
|
+
def self.chop_basename(pth)
|
53
|
+
result = Public.send(:chop_basename, pth)
|
54
|
+
result unless result.empty?
|
98
55
|
end
|
99
56
|
|
100
57
|
def self.entries(pth)
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
def self.extname(pth)
|
105
|
-
FasterPathname::Public.send(:extname, pth)
|
106
|
-
end
|
107
|
-
|
108
|
-
def self.has_trailing_separator?(pth)
|
109
|
-
FasterPathname::Public.send(:has_trailing_separator?, pth)
|
58
|
+
result = Public.send(:entries, pth)
|
59
|
+
return result if result
|
60
|
+
raise Errno::NOENT, "No such file or directory @ dir_initialize - #{pth}"
|
110
61
|
end
|
111
62
|
|
112
|
-
def self.
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
def self.relative?(pth)
|
117
|
-
FasterPathname::Public.send(:relative?, pth)
|
63
|
+
def self.entries_compat(pth)
|
64
|
+
result = Public.send(:entries_compat, pth)
|
65
|
+
return result if result
|
66
|
+
raise Errno::NOENT, "No such file or directory @ dir_initialize - #{pth}"
|
118
67
|
end
|
119
68
|
|
120
69
|
module Rust
|
121
|
-
extend
|
122
|
-
|
123
|
-
|
124
|
-
attach_function :rust_arch_bits, [], :int32
|
70
|
+
extend Fiddle::Importer
|
71
|
+
dlload FFI_LIBRARY
|
72
|
+
extern 'int rust_arch_bits()'
|
125
73
|
end
|
126
74
|
private_constant :Rust
|
127
75
|
end
|
@@ -2,6 +2,8 @@
|
|
2
2
|
# If the asset is not available and we can't compile it from this code then FAIL
|
3
3
|
# on require of 'faster_path' with a very clear message as to why."
|
4
4
|
|
5
|
+
require_relative './platform'
|
6
|
+
|
5
7
|
module FasterPath
|
6
8
|
module AssetResolution # BREAK IN CASE OF EMERGENCY ;-)
|
7
9
|
class << self
|
@@ -50,8 +52,7 @@ module FasterPath
|
|
50
52
|
end
|
51
53
|
|
52
54
|
def lib_file
|
53
|
-
|
54
|
-
"#{lib_dir}/#{prefix}faster_path.#{FFI::Platform::LIBSUFFIX}"
|
55
|
+
Platform.ffi_library()
|
55
56
|
end
|
56
57
|
end
|
57
58
|
end
|
@@ -38,10 +38,9 @@ module FasterPath
|
|
38
38
|
end
|
39
39
|
private :add_trailing_separator
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
# end if !!ENV['WITH_REGRESSION']
|
41
|
+
def children(with_dir=true)
|
42
|
+
FasterPath.children_compat(@path, with_dir)
|
43
|
+
end if !!ENV['WITH_REGRESSION']
|
45
44
|
|
46
45
|
def chop_basename(pth)
|
47
46
|
FasterPath.chop_basename(pth)
|
@@ -57,10 +56,9 @@ module FasterPath
|
|
57
56
|
FasterPath.directory?(@path)
|
58
57
|
end
|
59
58
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
# end if !!ENV['WITH_REGRESSION']
|
59
|
+
def entries
|
60
|
+
FasterPath.entries_compat(@path)
|
61
|
+
end if !!ENV['WITH_REGRESSION']
|
64
62
|
|
65
63
|
def has_trailing_separator?(pth)
|
66
64
|
FasterPath.has_trailing_separator?(pth)
|
@@ -34,10 +34,9 @@ module FasterPath
|
|
34
34
|
end
|
35
35
|
private :add_trailing_separator
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
# end if !!ENV['WITH_REGRESSION']
|
37
|
+
def children(with_dir=true)
|
38
|
+
FasterPath.children_compat(@path, with_dir)
|
39
|
+
end if !!ENV['WITH_REGRESSION']
|
41
40
|
|
42
41
|
def chop_basename(pth)
|
43
42
|
FasterPath.chop_basename(pth)
|
@@ -53,10 +52,9 @@ module FasterPath
|
|
53
52
|
FasterPath.directory?(@path)
|
54
53
|
end
|
55
54
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
# end if !!ENV['WITH_REGRESSION']
|
55
|
+
def entries
|
56
|
+
FasterPath.entries_compat(@path)
|
57
|
+
end if !!ENV['WITH_REGRESSION']
|
60
58
|
|
61
59
|
def has_trailing_separator?(pth)
|
62
60
|
FasterPath.has_trailing_separator?(pth)
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module FasterPath
|
2
|
+
module Platform
|
3
|
+
class << self
|
4
|
+
def ffi_library
|
5
|
+
file = [
|
6
|
+
lib_prefix,
|
7
|
+
"faster_path.",
|
8
|
+
lib_suffix
|
9
|
+
]
|
10
|
+
|
11
|
+
File.join(rust_release, file.join())
|
12
|
+
end
|
13
|
+
|
14
|
+
def operating_system
|
15
|
+
case host_os()
|
16
|
+
when /linux|bsd|solaris/
|
17
|
+
"linux"
|
18
|
+
when /darwin/
|
19
|
+
"darwin"
|
20
|
+
when /mingw|mswin/
|
21
|
+
"windows"
|
22
|
+
else
|
23
|
+
host_os()
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def lib_prefix
|
28
|
+
case operating_system()
|
29
|
+
when /windows/
|
30
|
+
''
|
31
|
+
when /cygwin/
|
32
|
+
'cyg'
|
33
|
+
else
|
34
|
+
'lib'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def lib_suffix
|
39
|
+
case operating_system()
|
40
|
+
when /darwin/
|
41
|
+
'dylib'
|
42
|
+
when /linux/
|
43
|
+
'so'
|
44
|
+
when /windows|cygwin/
|
45
|
+
'dll'
|
46
|
+
else
|
47
|
+
'so'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def rust_release
|
52
|
+
File.expand_path("../../target/release/", __dir__)
|
53
|
+
end
|
54
|
+
|
55
|
+
def host_os
|
56
|
+
RbConfig::CONFIG['host_os'].downcase
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/lib/faster_path/version.rb
CHANGED
data/src/helpers.rs
CHANGED
@@ -1,9 +1,13 @@
|
|
1
|
-
use ruru::{
|
1
|
+
use ruru::{RString, Object, Class};
|
2
2
|
|
3
|
-
pub fn
|
4
|
-
|
5
|
-
|
3
|
+
pub fn new_pathname_instance(path: &str) -> Class {
|
4
|
+
let mut path_instance = Class::from(
|
5
|
+
Class::from_existing("Pathname").send("allocate", None).value()
|
6
|
+
);
|
7
|
+
path_instance.instance_variable_set(
|
8
|
+
"@path",
|
9
|
+
RString::new(path).to_any_object()
|
10
|
+
);
|
6
11
|
|
7
|
-
|
8
|
-
Class::from_existing(klass).new_instance(params)
|
12
|
+
path_instance
|
9
13
|
}
|
data/src/lib.rs
CHANGED
@@ -10,7 +10,7 @@ extern crate ruru;
|
|
10
10
|
#[macro_use]
|
11
11
|
extern crate lazy_static;
|
12
12
|
|
13
|
-
|
13
|
+
module!(FasterPath);
|
14
14
|
|
15
15
|
mod helpers;
|
16
16
|
mod pathname;
|
@@ -24,12 +24,12 @@ mod prepend_prefix;
|
|
24
24
|
pub mod rust_arch_bits;
|
25
25
|
mod path_parsing;
|
26
26
|
|
27
|
-
use ruru::{
|
27
|
+
use ruru::{Module, Object, RString, Boolean, Array, AnyObject};
|
28
28
|
|
29
29
|
// r_ methods are on the core class and may evaluate instance variables or self
|
30
30
|
// pub_ methods must take all values as parameters
|
31
31
|
methods!(
|
32
|
-
|
32
|
+
FasterPath,
|
33
33
|
_itself,
|
34
34
|
|
35
35
|
fn pub_add_trailing_separator(pth: RString) -> RString {
|
@@ -46,11 +46,11 @@ methods!(
|
|
46
46
|
pathname::pn_basename(pth, ext)
|
47
47
|
}
|
48
48
|
|
49
|
-
fn pub_children(pth: RString, with_dir: Boolean) ->
|
49
|
+
fn pub_children(pth: RString, with_dir: Boolean) -> AnyObject {
|
50
50
|
pathname::pn_children(pth, with_dir)
|
51
51
|
}
|
52
52
|
|
53
|
-
fn pub_children_compat(pth: RString, with_dir: Boolean) ->
|
53
|
+
fn pub_children_compat(pth: RString, with_dir: Boolean) -> AnyObject {
|
54
54
|
pathname::pn_children_compat(pth, with_dir)
|
55
55
|
}
|
56
56
|
|
@@ -87,12 +87,12 @@ methods!(
|
|
87
87
|
// }
|
88
88
|
|
89
89
|
// pub_entries returns an array of String objects
|
90
|
-
fn pub_entries(pth: RString) ->
|
90
|
+
fn pub_entries(pth: RString) -> AnyObject {
|
91
91
|
pathname::pn_entries(pth)
|
92
92
|
}
|
93
93
|
|
94
94
|
// pub_entries_compat returns an array of Pathname objects
|
95
|
-
fn pub_entries_compat(pth: RString) ->
|
95
|
+
fn pub_entries_compat(pth: RString) -> AnyObject {
|
96
96
|
pathname::pn_entries_compat(pth)
|
97
97
|
}
|
98
98
|
|
@@ -146,28 +146,26 @@ methods!(
|
|
146
146
|
#[allow(non_snake_case)]
|
147
147
|
#[no_mangle]
|
148
148
|
pub extern "C" fn Init_faster_pathname(){
|
149
|
-
|
150
|
-
itself.define_nested_class("Public", None);
|
151
|
-
});
|
152
|
-
|
153
|
-
// Public methods
|
154
|
-
// * methods for refinements, monkeypatching
|
155
|
-
// * methods that need all values as parameters
|
156
|
-
Class::from_existing("FasterPathname").get_nested_class("Public").define(|itself| {
|
149
|
+
Module::from_existing("FasterPath").define(|itself| {
|
157
150
|
itself.def_self("absolute?", pub_is_absolute);
|
158
151
|
itself.def_self("add_trailing_separator", pub_add_trailing_separator);
|
159
|
-
itself.def_self("basename", pub_basename);
|
160
|
-
itself.def_self("children", pub_children);
|
161
|
-
itself.def_self("children_compat", pub_children_compat);
|
162
|
-
itself.def_self("chop_basename", pub_chop_basename);
|
163
152
|
itself.def_self("cleanpath_aggressive", pub_cleanpath_aggressive);
|
164
153
|
itself.def_self("directory?", pub_is_directory);
|
165
154
|
itself.def_self("dirname", pub_dirname);
|
166
|
-
itself.def_self("entries", pub_entries);
|
167
|
-
itself.def_self("entries_compat", pub_entries_compat);
|
168
155
|
itself.def_self("extname", pub_extname);
|
169
156
|
itself.def_self("has_trailing_separator?", pub_has_trailing_separator);
|
170
157
|
itself.def_self("plus", pub_plus);
|
171
158
|
itself.def_self("relative?", pub_is_relative);
|
159
|
+
itself.define_nested_class("Public", None);
|
160
|
+
});
|
161
|
+
|
162
|
+
// For methods requiring addition Ruby-side behavior
|
163
|
+
Module::from_existing("FasterPath").get_nested_class("Public").define(|itself| {
|
164
|
+
itself.def_self("basename", pub_basename);
|
165
|
+
itself.def_self("children", pub_children);
|
166
|
+
itself.def_self("children_compat", pub_children_compat);
|
167
|
+
itself.def_self("chop_basename", pub_chop_basename);
|
168
|
+
itself.def_self("entries", pub_entries);
|
169
|
+
itself.def_self("entries_compat", pub_entries_compat);
|
172
170
|
});
|
173
171
|
}
|
data/src/pathname.rs
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
use helpers
|
1
|
+
use helpers::new_pathname_instance;
|
2
2
|
use basename;
|
3
3
|
use chop_basename;
|
4
4
|
use cleanpath_aggressive;
|
@@ -7,7 +7,7 @@ use extname;
|
|
7
7
|
use plus;
|
8
8
|
|
9
9
|
use ruru;
|
10
|
-
use ruru::{RString, Boolean, Array};
|
10
|
+
use ruru::{RString, Boolean, Array, AnyObject, NilClass, Object};
|
11
11
|
use std::path::{MAIN_SEPARATOR,Path};
|
12
12
|
use std::fs;
|
13
13
|
|
@@ -41,16 +41,17 @@ pub fn pn_basename(pth: MaybeString, ext: MaybeString) -> RString {
|
|
41
41
|
)
|
42
42
|
}
|
43
43
|
|
44
|
-
pub fn pn_children(pth: MaybeString, with_dir: MaybeBoolean) ->
|
45
|
-
let rstring = pth.ok().unwrap_or(RString::new("."));
|
46
|
-
let val = rstring.to_str();
|
47
|
-
let mut with_directory = with_dir.ok().unwrap_or(Boolean::new(true)).to_bool();
|
48
|
-
if val == "." {
|
49
|
-
with_directory = false;
|
50
|
-
}
|
44
|
+
pub fn pn_children(pth: MaybeString, with_dir: MaybeBoolean) -> AnyObject {
|
51
45
|
let mut arr = Array::new();
|
46
|
+
let val = pth.ok().unwrap_or(RString::new("."));
|
47
|
+
let val = val.to_str();
|
52
48
|
|
53
49
|
if let Ok(entries) = fs::read_dir(val) {
|
50
|
+
let mut with_directory = with_dir.ok().unwrap_or(Boolean::new(true)).to_bool();
|
51
|
+
if val == "." {
|
52
|
+
with_directory = false;
|
53
|
+
}
|
54
|
+
|
54
55
|
for entry in entries {
|
55
56
|
if with_directory {
|
56
57
|
match entry {
|
@@ -64,41 +65,44 @@ pub fn pn_children(pth: MaybeString, with_dir: MaybeBoolean) -> Array {
|
|
64
65
|
};
|
65
66
|
}
|
66
67
|
}
|
68
|
+
|
69
|
+
arr.to_any_object()
|
70
|
+
} else {
|
71
|
+
// TODO: When ruru exceptions are available switch the exception logic
|
72
|
+
// from the Ruby side to the Rust side
|
73
|
+
NilClass::new().to_any_object()
|
67
74
|
}
|
68
|
-
arr
|
69
75
|
}
|
70
76
|
|
71
|
-
pub fn pn_children_compat(pth: MaybeString, with_dir: MaybeBoolean) ->
|
72
|
-
let rstring = pth.ok().unwrap_or(RString::new("."));
|
73
|
-
let val = rstring.to_str();
|
74
|
-
let mut with_directory = with_dir.ok().unwrap_or(Boolean::new(true)).to_bool();
|
75
|
-
if val == "." {
|
76
|
-
with_directory = false;
|
77
|
-
}
|
77
|
+
pub fn pn_children_compat(pth: MaybeString, with_dir: MaybeBoolean) -> AnyObject {
|
78
78
|
let mut arr = Array::new();
|
79
|
+
let val = pth.ok().unwrap_or(RString::new("."));
|
80
|
+
let val = val.to_str();
|
79
81
|
|
80
82
|
if let Ok(entries) = fs::read_dir(val) {
|
83
|
+
let mut with_directory = with_dir.ok().unwrap_or(Boolean::new(true)).to_bool();
|
84
|
+
if val == "." {
|
85
|
+
with_directory = false;
|
86
|
+
}
|
87
|
+
|
81
88
|
for entry in entries {
|
82
89
|
if with_directory {
|
83
|
-
|
84
|
-
|
85
|
-
class_new("Pathname", vec![str_to_any_obj(v.path().to_str().unwrap())])
|
86
|
-
);
|
87
|
-
},
|
88
|
-
_ => {}
|
90
|
+
if let Ok(v) = entry {
|
91
|
+
arr.push(new_pathname_instance(v.path().to_str().unwrap()));
|
89
92
|
};
|
90
93
|
} else {
|
91
|
-
|
92
|
-
|
93
|
-
class_new("Pathname", vec![str_to_any_obj(v.file_name().to_str().unwrap())])
|
94
|
-
);
|
95
|
-
},
|
96
|
-
_ => {}
|
94
|
+
if let Ok(v) = entry {
|
95
|
+
arr.push(new_pathname_instance(v.file_name().to_str().unwrap()));
|
97
96
|
};
|
98
97
|
}
|
99
98
|
}
|
99
|
+
|
100
|
+
arr.to_any_object()
|
101
|
+
} else {
|
102
|
+
// TODO: When ruru exceptions are available switch the exception logic
|
103
|
+
// from the Ruby side to the Rust side
|
104
|
+
NilClass::new().to_any_object()
|
100
105
|
}
|
101
|
-
arr
|
102
106
|
}
|
103
107
|
|
104
108
|
pub fn pn_chop_basename(pth: MaybeString) -> Array {
|
@@ -152,34 +156,44 @@ pub fn pn_dirname(pth: MaybeString) -> RString {
|
|
152
156
|
// NilClass::new()
|
153
157
|
// }
|
154
158
|
|
155
|
-
pub fn pn_entries(pth: MaybeString) ->
|
156
|
-
let files = fs::read_dir(pth.ok().unwrap_or(RString::new("")).to_str()).unwrap();
|
159
|
+
pub fn pn_entries(pth: MaybeString) -> AnyObject {
|
157
160
|
let mut arr = Array::new();
|
158
161
|
|
159
|
-
|
160
|
-
|
162
|
+
if let Ok(files) = fs::read_dir(pth.ok().unwrap_or(RString::new("")).to_str()) {
|
163
|
+
arr.push(RString::new("."));
|
164
|
+
arr.push(RString::new(".."));
|
161
165
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
+
for file in files {
|
167
|
+
let file_name_str = file.unwrap().file_name().into_string().unwrap();
|
168
|
+
arr.push(RString::new(&file_name_str[..]));
|
169
|
+
}
|
166
170
|
|
167
|
-
|
171
|
+
arr.to_any_object()
|
172
|
+
} else {
|
173
|
+
// TODO: When ruru exceptions are available switch the exception logic
|
174
|
+
// from the Ruby side to the Rust side
|
175
|
+
NilClass::new().to_any_object()
|
176
|
+
}
|
168
177
|
}
|
169
178
|
|
170
|
-
pub fn pn_entries_compat(pth: MaybeString) ->
|
171
|
-
let files = fs::read_dir(pth.ok().unwrap_or(RString::new("")).to_str()).unwrap();
|
179
|
+
pub fn pn_entries_compat(pth: MaybeString) -> AnyObject {
|
172
180
|
let mut arr = Array::new();
|
173
181
|
|
174
|
-
|
175
|
-
|
182
|
+
if let Ok(files) = fs::read_dir(pth.ok().unwrap_or(RString::new("")).to_str()) {
|
183
|
+
arr.push(new_pathname_instance("."));
|
184
|
+
arr.push(new_pathname_instance(".."));
|
176
185
|
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
186
|
+
for file in files {
|
187
|
+
let file_name_str = file.unwrap().file_name().into_string().unwrap();
|
188
|
+
arr.push(new_pathname_instance(&file_name_str));
|
189
|
+
}
|
181
190
|
|
182
|
-
|
191
|
+
arr.to_any_object()
|
192
|
+
} else {
|
193
|
+
// TODO: When ruru exceptions are available switch the exception logic
|
194
|
+
// from the Ruby side to the Rust side
|
195
|
+
NilClass::new().to_any_object()
|
196
|
+
}
|
183
197
|
}
|
184
198
|
|
185
199
|
pub fn pn_extname(pth: MaybeString) -> RString {
|
@@ -212,7 +226,12 @@ pub fn pn_has_trailing_separator(pth: MaybeString) -> Boolean {
|
|
212
226
|
|
213
227
|
// also need impl +
|
214
228
|
pub fn pn_plus(pth1: MaybeString, pth2: MaybeString) -> RString {
|
215
|
-
RString::new(
|
229
|
+
RString::new(
|
230
|
+
&plus::plus_paths(
|
231
|
+
pth1.ok().unwrap_or(RString::new("")).to_str(),
|
232
|
+
pth2.ok().unwrap_or(RString::new("")).to_str()
|
233
|
+
)[..]
|
234
|
+
)
|
216
235
|
}
|
217
236
|
|
218
237
|
// pub fn pn_prepend_prefix(prefix: MaybeString, relpath: MaybeString){}
|
@@ -235,3 +254,4 @@ pub fn pn_is_relative(pth: MaybeString) -> Boolean {
|
|
235
254
|
// pub fn pn_rmtree(pth: MaybeString) -> NilClass {
|
236
255
|
// NilClass::new()
|
237
256
|
// }
|
257
|
+
//
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faster_path
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel P. Clark
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-02-
|
11
|
+
date: 2018-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,20 +38,6 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '12.0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: ffi
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '1.9'
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '1.9'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: read_source
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -128,14 +114,14 @@ dependencies:
|
|
128
114
|
requirements:
|
129
115
|
- - "~>"
|
130
116
|
- !ruby/object:Gem::Version
|
131
|
-
version: 1.0
|
117
|
+
version: '1.0'
|
132
118
|
type: :development
|
133
119
|
prerelease: false
|
134
120
|
version_requirements: !ruby/object:Gem::Requirement
|
135
121
|
requirements:
|
136
122
|
- - "~>"
|
137
123
|
- !ruby/object:Gem::Version
|
138
|
-
version: 1.0
|
124
|
+
version: '1.0'
|
139
125
|
description: FasterPath is a reimplementation of Pathname for better performance.
|
140
126
|
email:
|
141
127
|
- 6ftdan@gmail.com
|
@@ -158,6 +144,7 @@ files:
|
|
158
144
|
- lib/faster_path/asset_resolution.rb
|
159
145
|
- lib/faster_path/optional/monkeypatches.rb
|
160
146
|
- lib/faster_path/optional/refinements.rb
|
147
|
+
- lib/faster_path/platform.rb
|
161
148
|
- lib/faster_path/version.rb
|
162
149
|
- src/basename.rs
|
163
150
|
- src/chop_basename.rs
|
@@ -191,7 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
191
178
|
version: '0'
|
192
179
|
requirements: []
|
193
180
|
rubyforge_project:
|
194
|
-
rubygems_version: 2.6
|
181
|
+
rubygems_version: 2.7.6
|
195
182
|
signing_key:
|
196
183
|
specification_version: 4
|
197
184
|
summary: Reimplementation of Pathname for better performance
|