nrser 0.3.6 → 0.3.7
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/lib/nrser/core_ext/pathname.rb +44 -15
- data/lib/nrser/core_ext/string.rb +50 -0
- data/lib/nrser/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea96a298163ec6b20a0437bc7ab7c8ea9200fd99
|
4
|
+
data.tar.gz: c6aabc018e890bfa791e20925b2c32240c4110d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29d05d08cc6d63ee707ad4ce1bf34b4b148a132ee669749ad1a01eb392ba1ef6d842c1be240cbf0ec2d514e3acd320c70e2f84e86376d93ad54a688ffa428244
|
7
|
+
data.tar.gz: 4dc97cdc270fc79692b1a7ffcba3c569ae3649247f78e16b128603933c40ebb05c925fe934b53a5c082f23788cde3444ba4cf7f082143b27274c53104647cac5
|
@@ -11,7 +11,13 @@ class Pathname
|
|
11
11
|
# true if the Pathname starts with any of the prefixes.
|
12
12
|
#
|
13
13
|
def start_with? *prefixes
|
14
|
-
to_s.start_with? *prefixes.map
|
14
|
+
to_s.start_with? *prefixes.map { |prefix|
|
15
|
+
if Pathname === prefix
|
16
|
+
prefix.to_s
|
17
|
+
else
|
18
|
+
prefix
|
19
|
+
end
|
20
|
+
}
|
15
21
|
end
|
16
22
|
|
17
23
|
|
@@ -49,29 +55,52 @@ class Pathname
|
|
49
55
|
end
|
50
56
|
|
51
57
|
|
52
|
-
#
|
53
|
-
#
|
54
|
-
# @param [type] arg_name
|
55
|
-
# @todo Add name param description.
|
56
|
-
#
|
57
|
-
# @return [return_type]
|
58
|
-
# @todo Document return value.
|
58
|
+
# See {NRSER.find_up}.
|
59
59
|
#
|
60
60
|
def find_up rel_path, **kwds
|
61
61
|
NRSER.find_up rel_path, **kwds, from: self
|
62
62
|
end # #find_root
|
63
63
|
|
64
64
|
|
65
|
-
#
|
66
|
-
#
|
67
|
-
# @param [type] arg_name
|
68
|
-
# @todo Add name param description.
|
69
|
-
#
|
70
|
-
# @return [return_type]
|
71
|
-
# @todo Document return value.
|
65
|
+
# See {NRSER.find_up!}.
|
72
66
|
#
|
73
67
|
def find_up! rel_path, **kwds
|
74
68
|
NRSER.find_up! rel_path, **kwds, from: self
|
75
69
|
end # #find_root
|
76
70
|
|
71
|
+
|
72
|
+
# Shortcut to convert into a relative pathname, by default from the working
|
73
|
+
# directory, with option to `./` prefix.
|
74
|
+
#
|
75
|
+
# @param [Pathname] base_dir:
|
76
|
+
# Directory you want the result to be relative to.
|
77
|
+
#
|
78
|
+
# @param [Boolean] dot_slash:
|
79
|
+
# When `true` will prepend `./` to the resulting path, unless it already
|
80
|
+
# starts with `../`.
|
81
|
+
#
|
82
|
+
# @return [Pathname]
|
83
|
+
#
|
84
|
+
def to_rel base_dir: Pathname.getwd, dot_slash: false
|
85
|
+
rel = relative_path_from base_dir
|
86
|
+
|
87
|
+
if dot_slash && !rel.start_with?( /\.\.?\// )
|
88
|
+
File.join( '.', rel ).to_pn
|
89
|
+
else
|
90
|
+
rel
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
# Just a quick cut for `.to_rel.to_s`, since I seem to use that sort of form
|
96
|
+
# a lot.
|
97
|
+
#
|
98
|
+
# @param (see #to_rel)
|
99
|
+
#
|
100
|
+
# @return [String]
|
101
|
+
#
|
102
|
+
def to_rel_s *args
|
103
|
+
to_rel( *args ).to_s
|
104
|
+
end
|
105
|
+
|
77
106
|
end # class Pathname
|
@@ -56,6 +56,56 @@ class String
|
|
56
56
|
end
|
57
57
|
|
58
58
|
|
59
|
+
# Alias the stdlib {#start_with?} 'cause we'll need to use it when
|
60
|
+
# redefining the method below.
|
61
|
+
#
|
62
|
+
alias_method :stdlib_start_with?, :start_with?
|
63
|
+
|
64
|
+
|
65
|
+
# Augment {#start_with?} to accept {Regexp} prefixes.
|
66
|
+
#
|
67
|
+
# I guess I always *just felt* like this should work... so now it does
|
68
|
+
# (kinda, at least).
|
69
|
+
#
|
70
|
+
# Everything should work the exact same for {String} prefixes.
|
71
|
+
#
|
72
|
+
# Use {Regexp} ones at your own pleasure and peril.
|
73
|
+
#
|
74
|
+
# @param [String | Regexp] *prefixes
|
75
|
+
# Strings behave as usual per the standard lib.
|
76
|
+
#
|
77
|
+
# Regexp sources are used to create a new Regexp with `\A` at the start -
|
78
|
+
# unless their source already starts with `\A` or `^` - and those Regexp
|
79
|
+
# are tested against the string.
|
80
|
+
#
|
81
|
+
# Regexp options are also copied over if a new Regexp is created. I can
|
82
|
+
# def imagine things getting weird with some exotic regular expression
|
83
|
+
# or another, but this feature is really indented for very simple patterns,
|
84
|
+
# for which it should suffice.
|
85
|
+
#
|
86
|
+
# @return [Boolean]
|
87
|
+
# `true` if `self` starts with *any* of the `prefixes`.
|
88
|
+
#
|
89
|
+
def start_with? *prefixes
|
90
|
+
unless prefixes.any? { |x| Regexp === x }
|
91
|
+
return stdlib_start_with? *prefixes
|
92
|
+
end
|
93
|
+
|
94
|
+
prefixes.any? { |prefix|
|
95
|
+
case prefix
|
96
|
+
when Regexp
|
97
|
+
unless prefix.source.start_with? '\A', '^'
|
98
|
+
prefix = Regexp.new( "\\A#{ prefix.source }", prefix.options )
|
99
|
+
end
|
100
|
+
|
101
|
+
prefix =~ self
|
102
|
+
else
|
103
|
+
stdlib_start_with? prefix
|
104
|
+
end
|
105
|
+
}
|
106
|
+
end
|
107
|
+
|
108
|
+
|
59
109
|
# @!group Unicode Stylization
|
60
110
|
# ==========================================================================
|
61
111
|
|
data/lib/nrser/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nrser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nrser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hamster
|