pathstring 0.0.1 → 0.0.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.
data/lib/pathstring.rb CHANGED
@@ -38,16 +38,17 @@ class Pathstring < String
38
38
  end
39
39
 
40
40
  def initialize(path, relative_path=nil)
41
+ stringified = path.to_s
41
42
  # first arg to String
42
- super path
43
+ super stringified
43
44
 
44
45
  # set relative origin, with '' as default
45
46
  # to allow setting absolute path in any case
46
47
  relative_root_with relative_path || ''
47
- absolute_with path
48
+ absolute_with stringified
48
49
 
49
50
  # if path argument is not absolute, then it's relative...
50
- relative_with path if absolute != path
51
+ relative_with stringified if absolute != stringified
51
52
  # if path argument is not set yet and we're given a relative_path argument
52
53
  relative_with @absolute.relative_path_from(@relative_root) if !@relative && relative_path
53
54
 
@@ -1,3 +1,3 @@
1
1
  class Pathstring < String
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,46 @@
1
+ # encoding: utf-8
2
+
3
+ require 'pathstring'
4
+
5
+ class PathstringRoot < Pathstring
6
+
7
+ # last selected element
8
+ attr_reader :last
9
+
10
+ attr_writer :element_class # ?
11
+
12
+ # Useful memoize.
13
+ # Needed to be done here because i
14
+ # really don't want to do it enroot
15
+ def select(path)
16
+ @last = enroot path
17
+ end
18
+
19
+ # instantiate with parameter and set the right facade
20
+ def enroot(path)
21
+ element_class.new(path, self).tap { |e| e.relative! }
22
+ end
23
+
24
+ # list of an element's children as instances of the
25
+ # elements class
26
+ def branching(path=nil)
27
+ join(path || @last || '').children.sort.map do |cell|
28
+ enroot(cell).tap { |c| yield c if block_given? }
29
+ end
30
+ rescue # yeah yeah... i know Errno::ENOTDIR, but i don't care enough
31
+ nil
32
+ end
33
+
34
+ private
35
+
36
+ def element_class
37
+ # inject is a funny way to do recursive stuff
38
+ # (here to find a constant starting from Object)
39
+ # Plip::Plap::PlopRoot will instantiate Plip::Plap::Plop objects
40
+ @element_class ||= self.class.name.sub(/Root$/, '').split('::').inject(Object) do |constant, chunk|
41
+ constant = constant.const_get chunk
42
+ end
43
+ end
44
+
45
+ end
46
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pathstring
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-29 00:00:00.000000000 Z
12
+ date: 2013-01-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pedlar
@@ -52,6 +52,7 @@ extra_rdoc_files: []
52
52
  files:
53
53
  - lib/pathstring.rb
54
54
  - lib/pathstring/version.rb
55
+ - lib/pathstring_root.rb
55
56
  homepage: https://github.com/lacravate/pathstring
56
57
  licenses: []
57
58
  post_install_message: