Class: Adva::Static::Import::Source::Path
- Inherits:
-
Pathname
- Object
- Pathname
- Adva::Static::Import::Source::Path
- Defined in:
- lib/adva/static/import/source/path.rb
Constant Summary collapse
- TYPES =
['html', 'jekyll', 'yml']
- EXTENSIONS =
TYPES.map { |type| ".#{type}" }
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
- #descendants ⇒ Object
- #filename ⇒ Object
- #find(name) ⇒ Object
- #glob ⇒ Object
- #gsub(pattern, replacement) ⇒ Object
-
#initialize(path, root = nil) ⇒ Path
constructor
A new instance of Path.
- #join(other) ⇒ Object
- #local ⇒ Object
- #parent ⇒ Object
- #parents ⇒ Object
- #root? ⇒ Boolean
- #self_and_descendants ⇒ Object
- #self_and_parents ⇒ Object
Constructor Details
Instance Attribute Details
#root ⇒ Object (readonly)
Returns the value of attribute root.
9 10 11 |
# File 'lib/adva/static/import/source/path.rb', line 9 def root @root end |
Instance Method Details
#<=>(other) ⇒ Object
73 74 75 |
# File 'lib/adva/static/import/source/path.rb', line 73 def <=>(other) root? ? -1 : other.root? ? 1 : to_s <=> other.to_s end |
#==(other) ⇒ Object
77 78 79 |
# File 'lib/adva/static/import/source/path.rb', line 77 def ==(other) to_s == other.to_s end |
#descendants ⇒ Object
41 42 43 |
# File 'lib/adva/static/import/source/path.rb', line 41 def descendants Dir[join("**/*.{#{TYPES.join(',')}}")].map { |child| join(child.gsub(/#{to_s}\/?/, '')) } end |
#filename ⇒ Object
49 50 51 |
# File 'lib/adva/static/import/source/path.rb', line 49 def filename basename.gsub(extname, '') end |
#find(name) ⇒ Object
68 69 70 71 |
# File 'lib/adva/static/import/source/path.rb', line 68 def find(name) path = Dir["#{join(name)}.{#{TYPES.join(',')}}"].first self.class.new(path, root) if path end |
#glob ⇒ Object
62 63 64 65 66 |
# File 'lib/adva/static/import/source/path.rb', line 62 def glob paths = Dir[join('**/*')].map { |child| join(child.gsub("#{to_s}/", '')) } paths = paths.map { |path| path.filename == 'index' ? path.parent : path } paths.sort end |
#gsub(pattern, replacement) ⇒ Object
58 59 60 |
# File 'lib/adva/static/import/source/path.rb', line 58 def gsub(pattern, replacement) self.class.new(to_s.gsub(pattern, replacement), root) end |
#join(other) ⇒ Object
53 54 55 56 |
# File 'lib/adva/static/import/source/path.rb', line 53 def join(other) self.class.new(super, root) # self.class.new(super(other.gsub(/^\//, '')), root) end |
#local ⇒ Object
45 46 47 |
# File 'lib/adva/static/import/source/path.rb', line 45 def local gsub(root ? "#{root}/" : '', '') end |
#parent ⇒ Object
24 25 26 |
# File 'lib/adva/static/import/source/path.rb', line 24 def parent self.class.new(super, @root || self) end |
#parents ⇒ Object
32 33 34 35 |
# File 'lib/adva/static/import/source/path.rb', line 32 def parents parts = to_s.split('/')[0..-2] parts.inject([]) { |parents, part| parents << self.class.new(parts[0..parents.size].join('/'), root) } end |
#root? ⇒ Boolean
16 17 18 |
# File 'lib/adva/static/import/source/path.rb', line 16 def root? !@root || filename == 'index' && parent.root? || @root.to_s == to_s # i.e. this is the root path if no root is set end |
#self_and_descendants ⇒ Object
37 38 39 |
# File 'lib/adva/static/import/source/path.rb', line 37 def self_and_descendants [self] + descendants end |
#self_and_parents ⇒ Object
28 29 30 |
# File 'lib/adva/static/import/source/path.rb', line 28 def self_and_parents parents << self end |