faster_path 0.1.1 → 0.1.2
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 +4 -4
- data/.gitignore +1 -0
- data/Cargo.toml +1 -1
- data/ext/faster_path/extconf.rb +2 -2
- data/faster_path.gemspec +3 -1
- data/lib/faster_path/optional/monkeypatches.rb +7 -1
- data/lib/faster_path/optional/refinements.rb +8 -0
- data/lib/faster_path/version.rb +1 -1
- data/lib/faster_path.rb +5 -1
- data/src/basename.rs +12 -5
- data/src/lib.rs +8 -2
- data/src/tools/chomp_pathish_regex.rs +38 -0
- metadata +34 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa3f9dba549d669279573d0241b6d2c682f79662
|
4
|
+
data.tar.gz: aa054bab991c3002071a7ec48d73088294f2b01d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea433ac9b113962f898e229af0a466f0b6c37136fcc709ed9ff0c07659c5515537c3747fffd518a88051c919c08757aada3b1b47f714af42aee15e85eccd9d6a
|
7
|
+
data.tar.gz: e813af21a48a83b4b278663a2e2ef4c7ce9874e682651ce3ef529165c923a4a84830c53341d9725757573e75e63ff0e6f1c921d5382d8ed67bd957fbcaf4d7a7
|
data/.gitignore
CHANGED
data/Cargo.toml
CHANGED
data/ext/faster_path/extconf.rb
CHANGED
@@ -11,9 +11,9 @@ unless find_executable('cargo')
|
|
11
11
|
END { puts "Exiting..."}
|
12
12
|
end
|
13
13
|
|
14
|
-
Dir.chdir(
|
14
|
+
Dir.chdir(File.expand_path("../../", File.dirname(__FILE__))) do
|
15
15
|
system("rake build_src")
|
16
16
|
system("rake clean_src")
|
17
17
|
end
|
18
18
|
|
19
|
-
create_makefile('faster_path/dummy')
|
19
|
+
create_makefile('faster_path/dummy')
|
data/faster_path.gemspec
CHANGED
@@ -19,9 +19,11 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.extensions << "ext/faster_path/extconf.rb"
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.add_dependency "ffi"
|
22
|
+
spec.add_dependency "ffi", "~> 1.9"
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.12"
|
24
24
|
spec.add_development_dependency "method_source", "~> 0.8.2"
|
25
25
|
spec.add_development_dependency "rake", "~> 11.1"
|
26
26
|
spec.add_development_dependency "minitest", "~> 5.8"
|
27
|
+
spec.add_development_dependency "minitest-reporters", "~> 1.1"
|
28
|
+
spec.add_development_dependency "color_pound_spec_reporter", "~> 0.0.5"
|
27
29
|
end
|
@@ -1,10 +1,16 @@
|
|
1
1
|
module FasterPath
|
2
2
|
def self.sledgehammer_everything!
|
3
|
+
::File.class_eval do
|
4
|
+
def basename(pth)
|
5
|
+
FasterPath.basename(pth)
|
6
|
+
end if FasterPath.respond_to? :basename
|
7
|
+
end unless true # No need to open class when we're not using it yet
|
8
|
+
|
3
9
|
::Pathname.class_eval do
|
4
10
|
def absolute?
|
5
11
|
FasterPath.absolute?(@path)
|
6
12
|
end
|
7
|
-
|
13
|
+
|
8
14
|
def chop_basename(pth)
|
9
15
|
FasterPath.chop_basename(pth)
|
10
16
|
end
|
@@ -1,4 +1,12 @@
|
|
1
1
|
module FasterPath
|
2
|
+
module RefineFile
|
3
|
+
refine File do
|
4
|
+
def basename(pth)
|
5
|
+
FasterPath.basename(pth)
|
6
|
+
end if FasterPath.respond_to? :basename
|
7
|
+
end
|
8
|
+
end unless true # No need to open class when we're not using it yet
|
9
|
+
|
2
10
|
module RefinePathname
|
3
11
|
refine Pathname do
|
4
12
|
def absolute?
|
data/lib/faster_path/version.rb
CHANGED
data/lib/faster_path.rb
CHANGED
@@ -26,6 +26,10 @@ module FasterPath
|
|
26
26
|
Rust.is_blank(str)
|
27
27
|
end
|
28
28
|
|
29
|
+
def self.basename(pth, ext="")
|
30
|
+
Rust.basename(pth, ext)
|
31
|
+
end unless true # WAY_TOO_SLOW! 5600X slower
|
32
|
+
|
29
33
|
# EXAMPLE
|
30
34
|
#def self.one_and_two
|
31
35
|
# Rust.one_and_two.to_a
|
@@ -52,7 +56,7 @@ module FasterPath
|
|
52
56
|
attach_function :is_relative, [ :string ], :bool
|
53
57
|
attach_function :is_blank, [ :string ], :bool
|
54
58
|
attach_function :both_are_blank, [ :string, :string ], :bool
|
55
|
-
attach_function :basename, [ :string ], :string
|
59
|
+
#attach_function :basename, [ :string, :string ], :string
|
56
60
|
attach_function :dirname, [ :string ], :string
|
57
61
|
attach_function :basename_for_chop, [ :string ], :string # decoupling behavior
|
58
62
|
attach_function :dirname_for_chop, [ :string ], :string # decoupling behavior
|
data/src/basename.rs
CHANGED
@@ -1,14 +1,21 @@
|
|
1
1
|
#[no_mangle]
|
2
|
-
pub extern fn basename(string: *const c_char) -> *const c_char {
|
3
|
-
let
|
2
|
+
pub extern fn basename(string: *const c_char, comp_ext: *const c_char) -> *const c_char {
|
3
|
+
let c_str1 = unsafe {
|
4
4
|
assert!(!string.is_null());
|
5
|
-
|
6
5
|
CStr::from_ptr(string)
|
7
6
|
};
|
7
|
+
let c_str2 = unsafe {
|
8
|
+
assert!(!comp_ext.is_null());
|
9
|
+
CStr::from_ptr(comp_ext)
|
10
|
+
};
|
11
|
+
let r_str = str::from_utf8(c_str1.to_bytes()).unwrap();
|
12
|
+
let r_str_chomp = str::from_utf8(c_str2.to_bytes()).unwrap();
|
8
13
|
|
9
|
-
let r_str =
|
14
|
+
let r_str = if !r_str_chomp.is_empty() {
|
15
|
+
chomp_pathish_regex(r_str, r_str_chomp)
|
16
|
+
} else { r_str.to_string() };
|
10
17
|
|
11
|
-
let part = Path::new(r_str).file_name().unwrap_or(OsStr::new("")).to_str();
|
18
|
+
let part = Path::new(&r_str[..]).file_name().unwrap_or(OsStr::new("")).to_str();
|
12
19
|
|
13
20
|
let output = CString::new(format!("{}", part.unwrap())).unwrap();
|
14
21
|
output.into_raw()
|
data/src/lib.rs
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
// Copyright 2015-2016 Daniel P. Clark & Other
|
1
|
+
// Copyright 2015-2016 Daniel P. Clark & Other FasterPath Developers
|
2
2
|
//
|
3
3
|
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
|
4
4
|
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
|
5
5
|
// http://opensource.org/licenses/MIT>, at your option. This file may not be
|
6
6
|
// copied, modified, or distributed except according to those terms.
|
7
7
|
extern crate libc;
|
8
|
+
//extern crate regex;
|
8
9
|
|
9
10
|
use std::path::{Path,MAIN_SEPARATOR};
|
10
11
|
use libc::c_char;
|
@@ -12,13 +13,18 @@ use std::ffi::{CStr,CString,OsStr};
|
|
12
13
|
use std::str;
|
13
14
|
use std::mem;
|
14
15
|
|
16
|
+
// Not including regex in current build so chomp_pathish_regex
|
17
|
+
// and basename will be excluded in build
|
18
|
+
//include!("tools/chomp_pathish_regex.rs");
|
19
|
+
//include!("basename.rs");
|
20
|
+
|
21
|
+
|
15
22
|
include!("ruby_string.rs");
|
16
23
|
include!("ruby_array.rs");
|
17
24
|
include!("is_absolute.rs");
|
18
25
|
include!("is_relative.rs");
|
19
26
|
include!("is_blank.rs");
|
20
27
|
include!("both_are_blank.rs");
|
21
|
-
include!("basename.rs");
|
22
28
|
include!("dirname.rs");
|
23
29
|
include!("basename_for_chop.rs");
|
24
30
|
include!("dirname_for_chop.rs");
|
@@ -0,0 +1,38 @@
|
|
1
|
+
fn chomp_pathish_regex(string: &str, globish_string: &str) -> String {
|
2
|
+
use regex::Regex;
|
3
|
+
// Keep first match of Regex pattern
|
4
|
+
// \A(?:(.*)(?:\.{1}\w+)|(.*))\z
|
5
|
+
let mut reg_builder: String = String::with_capacity(globish_string.len()+30); // need 29 chars + gs
|
6
|
+
reg_builder.push_str(r"\A(?:(.*)");
|
7
|
+
if globish_string.len() != 0 {
|
8
|
+
let mut gs = globish_string.chars();
|
9
|
+
loop {
|
10
|
+
match gs.next() {
|
11
|
+
Some('.') => { reg_builder.push_str(r"(?:\.{1}") },
|
12
|
+
Some('*') => { reg_builder.push_str(r"\w+") },
|
13
|
+
Some(x) => { reg_builder.push(x) },
|
14
|
+
None => {
|
15
|
+
reg_builder.push_str(r")|(.*)");
|
16
|
+
break
|
17
|
+
},
|
18
|
+
}
|
19
|
+
}
|
20
|
+
}
|
21
|
+
reg_builder.push_str(r")\z");
|
22
|
+
|
23
|
+
let re = Regex::new(®_builder[..]).unwrap();
|
24
|
+
let caps = re.captures(string).unwrap();
|
25
|
+
caps.at(1).unwrap_or(caps.at(0).unwrap_or("")).to_string()
|
26
|
+
}
|
27
|
+
|
28
|
+
#[test]
|
29
|
+
fn it_chomps_strings_correctly(){
|
30
|
+
assert_eq!(chomp_pathish_regex("",""), "");
|
31
|
+
assert_eq!(chomp_pathish_regex("ruby",""), "ruby");
|
32
|
+
assert_eq!(chomp_pathish_regex("ruby.rb",".rb"), "ruby");
|
33
|
+
assert_eq!(chomp_pathish_regex("ruby.rb",".*"), "ruby");
|
34
|
+
assert_eq!(chomp_pathish_regex(".ruby/ruby.rb",".rb"), ".ruby/ruby");
|
35
|
+
assert_eq!(chomp_pathish_regex(".ruby/ruby.rb.swp",".rb"), ".ruby/ruby.rb.swp");
|
36
|
+
assert_eq!(chomp_pathish_regex(".ruby/ruby.rb.swp",".swp"), ".ruby/ruby.rb");
|
37
|
+
assert_eq!(chomp_pathish_regex(".ruby/ruby.rb.swp",".*"), ".ruby/ruby.rb");
|
38
|
+
}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faster_path
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel P. Clark
|
@@ -14,16 +14,16 @@ dependencies:
|
|
14
14
|
name: ffi
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '1.9'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '1.9'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,6 +80,34 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '5.8'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: minitest-reporters
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.1'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.1'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: color_pound_spec_reporter
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.0.5
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.0.5
|
83
111
|
description: FasterPath is a reimplementation of Pathname for better performance.
|
84
112
|
email:
|
85
113
|
- 6ftdan@gmail.com
|
@@ -115,6 +143,7 @@ files:
|
|
115
143
|
- src/lib.rs
|
116
144
|
- src/ruby_array.rs
|
117
145
|
- src/ruby_string.rs
|
146
|
+
- src/tools/chomp_pathish_regex.rs
|
118
147
|
homepage: https://github.com/danielpclark/faster_path
|
119
148
|
licenses:
|
120
149
|
- MIT OR Apache-2.0
|