faster_path 0.2.0 → 0.2.1

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
  SHA1:
3
- metadata.gz: 4b227f5a94ba3ae27a33eab04fa65c80d95b9842
4
- data.tar.gz: 6cf955a639547780ecd12279dd50c8f00343b772
3
+ metadata.gz: 739814304e0316723938ab4430c07c7b17d490a2
4
+ data.tar.gz: 108e7bcbf3ff76a25cc13abcc93139c6aa605f8b
5
5
  SHA512:
6
- metadata.gz: 2571373e3f523f8db360b7b68593d192b10b4e718ba8f12cdc47292479c9e6facb74498d799dca7121aa4e895a7d2088b8d921855bd6857a3c9f1c7512617fcb
7
- data.tar.gz: 3e2c243a5921e93c3e0f47e028aa2e7b10cbdf5eb304830093e869a6abca1159b6b86dc627516c548e404b5ce738ecbc8fd2f5a5b5e48ef802d8e20a7c392d34
6
+ metadata.gz: 87faa82ae7729a586da191ee691e41db88a24269aa26e9ab54d0f823c5ce140bd105ecc91066dc0f0d5ee8a4dd883b030a8af17e85705d250dc9f6b8a0d53785
7
+ data.tar.gz: 3d1861b3bd1238270820b6b1f688da630ebfc5556afab69cc37b2eb62bc02f3fe6a4538f5d3605fc97d9afb60681f561f5d3e4a4b6e08c2b7600339bee85f4d0
data/README.md CHANGED
@@ -138,22 +138,22 @@ improvement result for the `chop_basename` method.
138
138
 
139
139
  Current methods implemented:
140
140
 
141
- |FasterPath Rust Implementation|Ruby 2.3.1 Implementation|Performance Improvement|
141
+ |FasterPath Rust Implementation|Ruby 2.3.4 Implementation|Time Shaved Off|
142
142
  |---|---|:---:|
143
- | `FasterPath.absolute?` | `Pathname#absolute?` | 93.9% |
144
- | `FasterPath.chop_basename` | `Pathname#chop_basename` | 50.6% |
145
- | `FasterPath.relative?` | `Pathname#relative?` | 93.2% |
146
- | `FasterPath.directory?` | `Pathname#directory?` | 25.5% |
147
- | `FasterPath.add_trailing_separator` | `Pathname#add_trailing_separator` | 46.8% |
148
- | `FasterPath.has_trailing_separator?` | `Pathname#has_trailing_separator` | 61.2% |
143
+ | `FasterPath.absolute?` | `Pathname#absolute?` | 88.5% |
144
+ | `FasterPath.add_trailing_separator` | `Pathname#add_trailing_separator` | 31.1% |
145
+ | `FasterPath.children` | `Pathname#children` | 13.6% |
146
+ | `FasterPath.chop_basename` | `Pathname#chop_basename` | 55.8% |
147
+ | `FasterPath.directory?` | `Pathname#directory?` | 12.7% |
148
+ | `FasterPath.entries` | `Pathname#entries` | 7.7% |
149
+ | `FasterPath.has_trailing_separator?` | `Pathname#has_trailing_separator` | 59.2% |
150
+ | `FasterPath.plus` | `Pathname#plus` | 77.5% |
151
+ | `FasterPath.relative?` | `Pathname#relative?` | 83.1% |
149
152
 
150
153
  You may choose to use the methods directly, or scope change to rewrite behavior on the
151
154
  standard library with the included refinements, or even call a method to monkeypatch
152
155
  everything everywhere.
153
156
 
154
- **Note:** `Pathname#chop_basename` in Ruby STDLIB has a bug with blank strings, that is the
155
- only difference in behavior against FasterPath's implementation.
156
-
157
157
  For the scoped **refinements** you will need to
158
158
 
159
159
  ```
@@ -26,14 +26,20 @@ module FasterPath
26
26
  end
27
27
  end
28
28
 
29
+ # rubocop:disable Metrics/MethodLength
29
30
  def self._ruby_library_pathname!
30
31
  ::Pathname.class_eval do
31
32
  def absolute?
32
33
  FasterPath.absolute?(@path)
33
34
  end
34
35
 
35
- def directory?
36
- FasterPath.directory?(@path)
36
+ def add_trailing_separator(pth)
37
+ FasterPath.add_trailing_separator(pth)
38
+ end
39
+ private :add_trailing_separator
40
+
41
+ def children(with_dir=true)
42
+ FasterPath.children(@path, with_dir)
37
43
  end
38
44
 
39
45
  def chop_basename(pth)
@@ -41,28 +47,27 @@ module FasterPath
41
47
  end
42
48
  private :chop_basename
43
49
 
44
- def relative?
45
- FasterPath.relative?(@path)
50
+ def directory?
51
+ FasterPath.directory?(@path)
46
52
  end
47
53
 
48
- def add_trailing_separator(pth)
49
- FasterPath.add_trailing_separator(pth)
54
+ def entries
55
+ FasterPath.entries(@path)
50
56
  end
51
- private :add_trailing_separator
52
57
 
53
58
  def has_trailing_separator?(pth)
54
59
  FasterPath.has_trailing_separator?(pth)
55
60
  end
56
61
  private :has_trailing_separator?
57
62
 
58
- def entries
59
- FasterPath.entries(@path)
60
- end
61
-
62
63
  def plus(pth, pth2)
63
64
  FasterPath.plus(pth, pth2)
64
65
  end
65
66
  private :plus
67
+
68
+ def relative?
69
+ FasterPath.relative?(@path)
70
+ end
66
71
  end
67
72
  end
68
73
  end
@@ -29,8 +29,13 @@ module FasterPath
29
29
  FasterPath.absolute?(@path)
30
30
  end
31
31
 
32
- def directory?
33
- FasterPath.directory?(@path)
32
+ def add_trailing_separator(pth)
33
+ FasterPath.add_trailing_separator(pth)
34
+ end
35
+ private :add_trailing_separator
36
+
37
+ def children(with_dir=true)
38
+ FasterPath.children(@path, with_dir)
34
39
  end
35
40
 
36
41
  def chop_basename(pth)
@@ -38,27 +43,26 @@ module FasterPath
38
43
  end
39
44
  private :chop_basename
40
45
 
41
- def relative?
42
- FasterPath.relative?(@path)
46
+ def directory?
47
+ FasterPath.directory?(@path)
43
48
  end
44
49
 
45
- def add_trailing_separator(pth)
46
- FasterPath.add_trailing_separator(pth)
50
+ def entries
51
+ FasterPath.entries(@path)
47
52
  end
48
- private :add_trailing_separator
49
53
 
50
54
  def has_trailing_separator?(pth)
51
55
  FasterPath.has_trailing_separator?(pth)
52
56
  end
53
57
 
54
- def entries
55
- FasterPath.entries(@path)
56
- end
57
-
58
58
  def plus(pth, pth2)
59
59
  FasterPath.plus(pth, pth2)
60
60
  end
61
61
  private :plus
62
+
63
+ def relative?
64
+ FasterPath.relative?(@path)
65
+ end
62
66
  end
63
67
  end
64
68
  end
@@ -1,3 +1,3 @@
1
1
  module FasterPath
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
data/lib/faster_path.rb CHANGED
@@ -14,14 +14,39 @@ module FasterPath
14
14
  new(library['Init_faster_pathname'], [], Fiddle::TYPE_VOIDP).
15
15
  call
16
16
 
17
- FasterPathname.class_eval do
17
+ FasterPathname::Public.class_eval do
18
+ private :absolute?
18
19
  private :add_trailing_separator
19
20
  private :basename
21
+ private :children
20
22
  private :chop_basename
23
+ private :directory?
21
24
  private :dirname
22
25
  private :entries
23
26
  private :extname
27
+ private :has_trailing_separator?
24
28
  private :plus
29
+ private :relative?
30
+ end
31
+
32
+ FasterPathname.class_eval do
33
+ def initialize(arg)
34
+ unless arg.is_a? String
35
+ arg = arg.to_s
36
+ end
37
+ raise(ArgumentError, "null byte found") if arg.include?("\0")
38
+ @path = arg
39
+ end
40
+
41
+ # BAD; exposes private methods
42
+ # Need to reprivatize specific methods
43
+ def method_missing(method_name, *a, &b)
44
+ Public.send(method_name, @path, *a, &b)
45
+ end
46
+
47
+ def respond_to?(method_name, include_private = false)
48
+ Public.send(:respond_to?, method_name) || super
49
+ end
25
50
  end
26
51
 
27
52
  def self.rust_arch_bits
@@ -33,11 +58,11 @@ module FasterPath
33
58
  end
34
59
 
35
60
  def self.absolute?(pth)
36
- FasterPathname.allocate.send(:absolute?, pth)
61
+ FasterPathname::Public.allocate.send(:absolute?, pth)
37
62
  end
38
63
 
39
64
  def self.add_trailing_separator(pth)
40
- FasterPathname.allocate.send(:add_trailing_separator, pth)
65
+ FasterPathname::Public.allocate.send(:add_trailing_separator, pth)
41
66
  end
42
67
 
43
68
  def self.blank?(str)
@@ -45,40 +70,44 @@ module FasterPath
45
70
  end
46
71
 
47
72
  def self.basename(pth, ext="")
48
- FasterPathname.allocate.send(:basename, pth, ext)
73
+ FasterPathname::Public.allocate.send(:basename, pth, ext)
74
+ end
75
+
76
+ def self.children(pth, with_directory=true)
77
+ FasterPathname::Public.allocate.send(:children, pth, with_directory)
49
78
  end
50
79
 
51
80
  def self.chop_basename(pth)
52
- result = FasterPathname.allocate.send(:chop_basename, pth)
81
+ result = FasterPathname::Public.allocate.send(:chop_basename, pth)
53
82
  result unless result.empty?
54
83
  end
55
84
 
56
85
  def self.directory?(pth)
57
- FasterPathname.allocate.send(:directory?, pth)
86
+ FasterPathname::Public.allocate.send(:directory?, pth)
58
87
  end
59
88
 
60
89
  def self.dirname(pth)
61
- FasterPathname.allocate.send(:dirname, pth)
90
+ FasterPathname::Public.allocate.send(:dirname, pth)
62
91
  end
63
92
 
64
93
  def self.entries(pth)
65
- FasterPathname.allocate.send(:entries, pth)
94
+ FasterPathname::Public.allocate.send(:entries, pth)
66
95
  end
67
96
 
68
97
  def self.extname(pth)
69
- FasterPathname.allocate.send(:extname, pth)
98
+ FasterPathname::Public.allocate.send(:extname, pth)
70
99
  end
71
100
 
72
101
  def self.has_trailing_separator?(pth)
73
- FasterPathname.allocate.send(:has_trailing_separator?, pth)
102
+ FasterPathname::Public.allocate.send(:has_trailing_separator?, pth)
74
103
  end
75
104
 
76
105
  def self.plus(pth, pth2)
77
- FasterPathname.allocate.send(:plus, pth, pth2)
106
+ FasterPathname::Public.allocate.send(:plus, pth, pth2)
78
107
  end
79
108
 
80
109
  def self.relative?(pth)
81
- FasterPathname.allocate.send(:relative?, pth)
110
+ FasterPathname::Public.allocate.send(:relative?, pth)
82
111
  end
83
112
 
84
113
  module Rust
data/src/lib.rs CHANGED
@@ -9,6 +9,7 @@ extern crate ruru;
9
9
 
10
10
  class!(FasterPathname);
11
11
 
12
+ mod pathname;
12
13
  mod basename;
13
14
  mod chop_basename;
14
15
  mod dirname;
@@ -18,126 +19,151 @@ pub mod rust_arch_bits;
18
19
  mod path_parsing;
19
20
 
20
21
  use ruru::{Class, Object, RString, Boolean, Array};
21
- use std::path::{MAIN_SEPARATOR,Path};
22
- use std::fs;
23
22
 
23
+ // r_ methods are on the core class and may evaluate instance variables or self
24
+ // pub_ methods must take all values as parameters
24
25
  methods!(
25
26
  FasterPathname,
26
27
  _itself,
27
28
 
28
- fn r_add_trailing_separator(pth: RString) -> RString {
29
- let p = pth.ok().unwrap();
30
- let x = format!("{}{}", p.to_str(), "a");
31
- match x.rsplit_terminator(MAIN_SEPARATOR).next() {
32
- Some("a") => p,
33
- _ => RString::new(format!("{}{}", p.to_str(), MAIN_SEPARATOR).as_str())
34
- }
29
+ // TOPATH = :to_path
30
+
31
+ // SAME_PATHS = if File::FNM_SYSCASE.nonzero?
32
+ // # Avoid #zero? here because #casecmp can return nil.
33
+ // proc {|a, b| a.casecmp(b) == 0}
34
+ // else
35
+ // proc {|a, b| a == b}
36
+ // end
37
+
38
+ // if File::ALT_SEPARATOR
39
+ // SEPARATOR_LIST = "#{Regexp.quote File::ALT_SEPARATOR}#{Regexp.quote File::SEPARATOR}"
40
+ // SEPARATOR_PAT = /[#{SEPARATOR_LIST}]/
41
+ // else
42
+ // SEPARATOR_LIST = "#{Regexp.quote File::SEPARATOR}"
43
+ // SEPARATOR_PAT = /#{Regexp.quote File::SEPARATOR}/
44
+ // end
45
+
46
+ fn pub_add_trailing_separator(pth: RString) -> RString {
47
+ pathname::pn_add_trailing_separator(pth)
35
48
  }
36
49
 
37
- fn r_is_absolute(pth: RString) -> Boolean {
38
- Boolean::new(match pth.ok().unwrap_or(RString::new("")).to_str().chars().next() {
39
- Some(c) => c == MAIN_SEPARATOR,
40
- None => false
41
- })
50
+ fn pub_is_absolute(pth: RString) -> Boolean {
51
+ pathname::pn_is_absolute(pth)
42
52
  }
43
53
 
44
- fn r_basename(pth: RString, ext: RString) -> RString {
45
- RString::new(
46
- &basename::basename(
47
- pth.ok().unwrap_or(RString::new("")).to_str(),
48
- ext.ok().unwrap_or(RString::new("")).to_str()
49
- )[..]
50
- )
54
+ // fn r_ascend(){}
55
+
56
+ fn pub_basename(pth: RString, ext: RString) -> RString {
57
+ pathname::pn_basename(pth, ext)
51
58
  }
52
59
 
53
- fn r_chop_basename(pth: RString) -> Array {
54
- let mut arr = Array::with_capacity(2);
55
- let results = chop_basename::chop_basename(pth.ok().unwrap_or(RString::new("")).to_str());
56
- match results {
57
- Some((dirname, basename)) => {
58
- arr.push(RString::new(&dirname[..]));
59
- arr.push(RString::new(&basename[..]));
60
- arr
61
- },
62
- None => arr
63
- }
60
+ fn pub_children(pth: RString, with_dir: Boolean) -> Array {
61
+ pathname::pn_children(pth, with_dir)
64
62
  }
65
63
 
66
- fn r_is_directory(pth: RString) -> Boolean {
67
- Boolean::new(
68
- Path::new(
69
- pth.ok().unwrap_or(RString::new("")).to_str()
70
- ).is_dir()
71
- )
64
+ fn pub_chop_basename(pth: RString) -> Array {
65
+ pathname::pn_chop_basename(pth)
72
66
  }
73
67
 
74
- fn r_dirname(pth: RString) -> RString {
75
- RString::new(
76
- &dirname::dirname(
77
- pth.ok().unwrap_or(RString::new("")).to_str()
78
- )[..]
79
- )
68
+ // fn r_cleanpath(){ pub_cleanpath(r_to_path()) }
69
+ // fn pub_cleanpath(pth: RString){}
70
+
71
+ // fn r_cleanpath_aggressive(pth: RString){}
72
+
73
+ // fn r_cleanpath_conservative(pth: RString){}
74
+
75
+ // fn r_del_trailing_separator(pth: RString){}
76
+
77
+ // fn r_descend(){}
78
+
79
+ fn pub_is_directory(pth: RString) -> Boolean {
80
+ pathname::pn_is_directory(pth)
80
81
  }
81
82
 
82
- fn r_entries(pth: RString) -> Array {
83
- let files = fs::read_dir(pth.ok().unwrap_or(RString::new("")).to_str()).unwrap();
84
- let mut arr = Array::new();
83
+ fn pub_dirname(pth: RString) -> RString {
84
+ pathname::pn_dirname(pth)
85
+ }
85
86
 
86
- arr.push(RString::new("."));
87
- arr.push(RString::new(".."));
87
+ // fn r_each_child(){}
88
+ // fn pub_each_child(){}
88
89
 
89
- for file in files {
90
- let file_name_str = file.unwrap().file_name().into_string().unwrap();
91
- arr.push(RString::new(&file_name_str[..]));
92
- }
90
+ // fn pub_each_filename(pth: RString) -> NilClass {
91
+ // pathname::pn_each_filename(pth)
92
+ // }
93
93
 
94
- arr
94
+ fn pub_entries(pth: RString) -> Array {
95
+ pathname::pn_entries(pth)
95
96
  }
96
97
 
97
- fn r_extname(pth: RString) -> RString {
98
- RString::new(
99
- &extname::extname(pth.ok().unwrap_or(RString::new("")).to_str())[..]
100
- )
98
+ fn pub_extname(pth: RString) -> RString {
99
+ pathname::pn_extname(pth)
101
100
  }
102
101
 
103
- fn r_has_trailing_separator(pth: RString) -> Boolean {
104
- let v = pth.ok().unwrap_or(RString::new(""));
105
- match chop_basename::chop_basename(v.to_str()) {
106
- Some((a,b)) => {
107
- Boolean::new(a.len() + b.len() < v.to_str().len())
108
- },
109
- _ => Boolean::new(false)
110
- }
102
+ // fn r_find(ignore_error: Boolean){}
103
+ // fn pub_find(pth: RString ,ignore_error: Boolean){}
104
+
105
+ fn pub_has_trailing_separator(pth: RString) -> Boolean {
106
+ pathname::pn_has_trailing_separator(pth)
111
107
  }
112
108
 
113
- fn r_plus(pth1: RString, pth2: RString) -> RString {
114
- RString::new(&plus::plus_paths(pth1.ok().unwrap().to_str(), pth2.ok().unwrap().to_str())[..])
109
+ // fn r_join(args: Array){}
110
+
111
+ // fn pub_mkpath(pth: RString) -> NilClass {
112
+ // pathname::pn_mkpath(pth)
113
+ // }
114
+
115
+ // fn r_is_mountpoint(){ pub_is_mountpount(r_to_path()) }
116
+ // fn pub_is_mountpoint(pth: RString){}
117
+
118
+ // fn r_parent(){ pub_parent(r_to_path()) }
119
+ // fn pub_parent(pth: RString){}
120
+
121
+ // also need impl +
122
+ fn pub_plus(pth1: RString, pth2: RString) -> RString {
123
+ pathname::pn_plus(pth1, pth2)
115
124
  }
116
125
 
117
- fn r_is_relative(pth: RString) -> Boolean {
118
- Boolean::new(
119
- match pth.ok().unwrap_or(RString::new(&MAIN_SEPARATOR.to_string()[..])).to_str().chars().next() {
120
- Some(c) => c != MAIN_SEPARATOR,
121
- None => true
122
- }
123
- )
126
+ // fn r_prepend_prefix(prefix: RString, relpath: RString){}
127
+
128
+ fn pub_is_relative(pth: RString) -> Boolean {
129
+ pathname::pn_is_relative(pth)
124
130
  }
131
+
132
+ // fn r_root(){ pub_root(r_to_path()) }
133
+ // fn pub_root(pth: RString){}
134
+
135
+ // fn r_split_names(pth: RString){}
136
+
137
+ // fn r_relative_path_from(){}
138
+ // fn pub_relative_path_from(){}
139
+
140
+ // fn pub_rmtree(pth: RString) -> NilClass {
141
+ // pathname::pn_rmtree(pth)
142
+ // }
125
143
  );
126
144
 
127
145
  #[allow(non_snake_case)]
128
146
  #[no_mangle]
129
147
  pub extern "C" fn Init_faster_pathname(){
130
148
  Class::new("FasterPathname", None).define(|itself| {
131
- itself.def("absolute?", r_is_absolute);
132
- itself.def("add_trailing_separator", r_add_trailing_separator);
133
- itself.def("basename", r_basename);
134
- itself.def("chop_basename", r_chop_basename);
135
- itself.def("directory?", r_is_directory);
136
- itself.def("dirname", r_dirname);
137
- itself.def("entries", r_entries);
138
- itself.def("extname", r_extname);
139
- itself.def("has_trailing_separator?", r_has_trailing_separator);
140
- itself.def("plus", r_plus);
141
- itself.def("relative?", r_is_relative);
149
+ itself.define_nested_class("Public", None);
150
+ });
151
+
152
+ // Public methods
153
+ // * methods for refinements, monkeypatching
154
+ // * methods that need all values as parameters
155
+ Class::from_existing("FasterPathname").get_nested_class("Public").define(|itself| {
156
+ itself.def("absolute?", pub_is_absolute);
157
+ itself.def("add_trailing_separator", pub_add_trailing_separator);
158
+ itself.def("basename", pub_basename);
159
+ itself.def("children", pub_children);
160
+ itself.def("chop_basename", pub_chop_basename);
161
+ itself.def("directory?", pub_is_directory);
162
+ itself.def("dirname", pub_dirname);
163
+ itself.def("entries", pub_entries);
164
+ itself.def("extname", pub_extname);
165
+ itself.def("has_trailing_separator?", pub_has_trailing_separator);
166
+ itself.def("plus", pub_plus);
167
+ itself.def("relative?", pub_is_relative);
142
168
  });
143
169
  }
data/src/pathname.rs ADDED
@@ -0,0 +1,179 @@
1
+ use basename;
2
+ use chop_basename;
3
+ use dirname;
4
+ use extname;
5
+ use plus;
6
+
7
+ use ruru;
8
+ use ruru::{RString, Boolean, Array};
9
+ use std::path::{MAIN_SEPARATOR,Path};
10
+ use std::fs;
11
+
12
+ pub fn pn_add_trailing_separator(pth: Result<ruru::RString, ruru::result::Error>) -> RString {
13
+ let p = pth.ok().unwrap();
14
+ let x = format!("{}{}", p.to_str(), "a");
15
+ match x.rsplit_terminator(MAIN_SEPARATOR).next() {
16
+ Some("a") => p,
17
+ _ => RString::new(format!("{}{}", p.to_str(), MAIN_SEPARATOR).as_str())
18
+ }
19
+ }
20
+
21
+ pub fn pn_is_absolute(pth: Result<ruru::RString, ruru::result::Error>) -> Boolean {
22
+ Boolean::new(match pth.ok().unwrap_or(RString::new("")).to_str().chars().next() {
23
+ Some(c) => c == MAIN_SEPARATOR,
24
+ None => false
25
+ })
26
+ }
27
+
28
+ // pub fn pn_ascend(){}
29
+
30
+ pub fn pn_basename(pth: Result<ruru::RString, ruru::result::Error>, ext: Result<ruru::RString, ruru::result::Error>) -> RString {
31
+ RString::new(
32
+ &basename::basename(
33
+ pth.ok().unwrap_or(RString::new("")).to_str(),
34
+ ext.ok().unwrap_or(RString::new("")).to_str()
35
+ )[..]
36
+ )
37
+ }
38
+
39
+ pub fn pn_children(pth: Result<ruru::RString, ruru::result::Error>, with_dir: Result<ruru::Boolean, ruru::result::Error>) -> Array {
40
+ let rstring = pth.ok().unwrap_or(RString::new("."));
41
+ let val = rstring.to_str();
42
+ let mut with_directory = with_dir.ok().unwrap_or(Boolean::new(true)).to_bool();
43
+ if val == "." {
44
+ with_directory = false;
45
+ }
46
+ let mut arr = Array::new();
47
+
48
+ if let Ok(entries) = fs::read_dir(val) {
49
+ for entry in entries {
50
+ if with_directory {
51
+ match entry {
52
+ Ok(v) => { arr.push(RString::new(v.path().to_str().unwrap())); },
53
+ _ => {}
54
+ };
55
+ } else {
56
+ match entry {
57
+ Ok(v) => { arr.push(RString::new(v.file_name().to_str().unwrap())); },
58
+ _ => {}
59
+ };
60
+ }
61
+ }
62
+ }
63
+ arr
64
+ }
65
+
66
+ pub fn pn_chop_basename(pth: Result<ruru::RString, ruru::result::Error>) -> Array {
67
+ let mut arr = Array::with_capacity(2);
68
+ let results = chop_basename::chop_basename(pth.ok().unwrap_or(RString::new("")).to_str());
69
+ match results {
70
+ Some((dirname, basename)) => {
71
+ arr.push(RString::new(&dirname[..]));
72
+ arr.push(RString::new(&basename[..]));
73
+ arr
74
+ },
75
+ None => arr
76
+ }
77
+ }
78
+
79
+ // pub fn pn_cleanpath(pth: Result<ruru::RString, ruru::result::Error>){}
80
+
81
+ // pub fn pn_cleanpath_aggressive(pth: Result<ruru::RString, ruru::result::Error>){}
82
+
83
+ // pub fn pn_cleanpath_conservative(pth: Result<ruru::RString, ruru::result::Error>){}
84
+
85
+ // pub fn pn_del_trailing_separator(pth: Result<ruru::RString, ruru::result::Error>){}
86
+
87
+ // pub fn pn_descend(){}
88
+
89
+ pub fn pn_is_directory(pth: Result<ruru::RString, ruru::result::Error>) -> Boolean {
90
+ Boolean::new(
91
+ Path::new(
92
+ pth.ok().unwrap_or(RString::new("")).to_str()
93
+ ).is_dir()
94
+ )
95
+ }
96
+
97
+ pub fn pn_dirname(pth: Result<ruru::RString, ruru::result::Error>) -> RString {
98
+ RString::new(
99
+ &dirname::dirname(
100
+ pth.ok().unwrap_or(RString::new("")).to_str()
101
+ )[..]
102
+ )
103
+ }
104
+
105
+ // pub fn pn_each_child(){}
106
+
107
+ // pub fn pn_each_filename(pth: Result<ruru::RString, ruru::result::Error>) -> NilClass {
108
+ // NilClass::new()
109
+ // }
110
+
111
+ pub fn pn_entries(pth: Result<ruru::RString, ruru::result::Error>) -> Array {
112
+ let files = fs::read_dir(pth.ok().unwrap_or(RString::new("")).to_str()).unwrap();
113
+ let mut arr = Array::new();
114
+
115
+ arr.push(RString::new("."));
116
+ arr.push(RString::new(".."));
117
+
118
+ for file in files {
119
+ let file_name_str = file.unwrap().file_name().into_string().unwrap();
120
+ arr.push(RString::new(&file_name_str[..]));
121
+ }
122
+
123
+ arr
124
+ }
125
+
126
+ pub fn pn_extname(pth: Result<ruru::RString, ruru::result::Error>) -> RString {
127
+ RString::new(
128
+ &extname::extname(pth.ok().unwrap_or(RString::new("")).to_str())[..]
129
+ )
130
+ }
131
+
132
+ // pub fn pn_find(pth: Result<ruru::RString, ruru::result::Error> ,ignore_error: Boolean){}
133
+
134
+ pub fn pn_has_trailing_separator(pth: Result<ruru::RString, ruru::result::Error>) -> Boolean {
135
+ let v = pth.ok().unwrap_or(RString::new(""));
136
+ match chop_basename::chop_basename(v.to_str()) {
137
+ Some((a,b)) => {
138
+ Boolean::new(a.len() + b.len() < v.to_str().len())
139
+ },
140
+ _ => Boolean::new(false)
141
+ }
142
+ }
143
+
144
+ // pub fn pn_join(args: Array){}
145
+
146
+ // pub fn pn_mkpath(pth: Result<ruru::RString, ruru::result::Error>) -> NilClass {
147
+ // NilClass::new()
148
+ // }
149
+
150
+ // pub fn pn_is_mountpoint(pth: Result<ruru::RString, ruru::result::Error>){}
151
+
152
+ // pub fn pn_parent(pth: Result<ruru::RString, ruru::result::Error>){}
153
+
154
+ // also need impl +
155
+ pub fn pn_plus(pth1: Result<ruru::RString, ruru::result::Error>, pth2: Result<ruru::RString, ruru::result::Error>) -> RString {
156
+ RString::new(&plus::plus_paths(pth1.ok().unwrap().to_str(), pth2.ok().unwrap().to_str())[..])
157
+ }
158
+
159
+ // pub fn pn_prepend_prefix(prefix: Result<ruru::RString, ruru::result::Error>, relpath: Result<ruru::RString, ruru::result::Error>){}
160
+
161
+ pub fn pn_is_relative(pth: Result<ruru::RString, ruru::result::Error>) -> Boolean {
162
+ Boolean::new(
163
+ match pth.ok().unwrap_or(RString::new(&MAIN_SEPARATOR.to_string()[..])).to_str().chars().next() {
164
+ Some(c) => c != MAIN_SEPARATOR,
165
+ None => true
166
+ }
167
+ )
168
+ }
169
+
170
+ // pub fn pn_root(pth: Result<ruru::RString, ruru::result::Error>){}
171
+
172
+ // pub fn pn_split_names(pth: Result<ruru::RString, ruru::result::Error>){}
173
+
174
+ // pub fn pn_relative_path_from(){}
175
+
176
+ // pub fn pn_rmtree(pth: Result<ruru::RString, ruru::result::Error>) -> NilClass {
177
+ // NilClass::new()
178
+ // }
179
+
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.0
4
+ version: 0.2.1
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: 2017-09-12 00:00:00.000000000 Z
11
+ date: 2017-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -179,6 +179,7 @@ files:
179
179
  - src/extname.rs
180
180
  - src/lib.rs
181
181
  - src/path_parsing.rs
182
+ - src/pathname.rs
182
183
  - src/plus.rs
183
184
  - src/rust_arch_bits.rs
184
185
  homepage: https://github.com/danielpclark/faster_path