Class: Webgen::Path
Overview
A path object provides information about a specific path as well as methods for accessing its content.
A webgen source class needs to derive a specialized path class from this class and implement an approriate #changed? method that returns true if the path’s content has changed since the last webgen run.
Direct Known Subclasses
Defined Under Namespace
Classes: SourceIO
Instance Attribute Summary collapse
-
#basename ⇒ Object
The basename part of the path.
-
#cnbase ⇒ Object
The canonical name without the extension.
-
#directory ⇒ Object
The directory part of the path.
-
#ext ⇒ Object
The extension.
-
#meta_info ⇒ Object
Extracted meta information for the path.
-
#path ⇒ Object
The full source path.
Class Method Summary collapse
-
.lcn(cn, lang) ⇒ Object
Utility method for creating the lcn from
cnand the languagelang.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Implemented sothat a Path looks like a String when used as key in a hash.
-
#==(other) ⇒ Object
(also: #eql?)
Compare this object to another Path or a String.
-
#=~(pattern) ⇒ Object
Return
trueif the localized path matches the givenpattern. -
#changed? ⇒ Boolean
Has the content of this path changed since the last webgen run? This default implementation always returns
true, a specialized sub class needs to override this behaviour!. -
#cn ⇒ Object
The canonical name created from the filename (created from cnbase and extension).
-
#dup ⇒ Object
Duplicate the path object.
-
#hash ⇒ Object
Implemented sothat a Path looks like a String when used as key in a hash.
-
#initialize(path, &ioblock) ⇒ Path
constructor
Create a new Path object for
path. -
#inspect ⇒ Object
:nodoc:.
-
#io ⇒ Object
The IO object associated with the path.
-
#lcn ⇒ Object
The localized canonical name created from the filename.
-
#mount_at(mp, prefix = nil) ⇒ Object
Mount this path at the mount point
mpoptionally strippingprefixfrom the path and return the new path object. -
#to_s ⇒ Object
(also: #to_str)
:nodoc:.
Constructor Details
#initialize(path, &ioblock) ⇒ Path
Create a new Path object for path. The optional block needs to return an IO object for the content of the path.
60 61 62 63 64 |
# File 'lib/webgen/path.rb', line 60 def initialize(path, &ioblock) = {} @io = SourceIO.new(&ioblock) if block_given? analyse(path) end |
Instance Attribute Details
#basename ⇒ Object
The basename part of the path.
44 45 46 |
# File 'lib/webgen/path.rb', line 44 def basename @basename end |
#cnbase ⇒ Object
The canonical name without the extension.
50 51 52 |
# File 'lib/webgen/path.rb', line 50 def cnbase @cnbase end |
#directory ⇒ Object
The directory part of the path.
47 48 49 |
# File 'lib/webgen/path.rb', line 47 def directory @directory end |
#ext ⇒ Object
The extension.
53 54 55 |
# File 'lib/webgen/path.rb', line 53 def ext @ext end |
#meta_info ⇒ Object
Extracted meta information for the path.
56 57 58 |
# File 'lib/webgen/path.rb', line 56 def end |
#path ⇒ Object
The full source path.
41 42 43 |
# File 'lib/webgen/path.rb', line 41 def path @path end |
Class Method Details
.lcn(cn, lang) ⇒ Object
Utility method for creating the lcn from cn and the language lang.
109 110 111 112 113 114 115 |
# File 'lib/webgen/path.rb', line 109 def self.lcn(cn, lang) if lang.nil? cn else cn.split('.').insert(1, lang.to_s).join('.') end end |
Instance Method Details
#<=>(other) ⇒ Object
Implemented sothat a Path looks like a String when used as key in a hash.
141 142 143 |
# File 'lib/webgen/path.rb', line 141 def <=>(other) @path <=> other.to_str end |
#==(other) ⇒ Object Also known as: eql?
Compare this object to another Path or a String.
123 124 125 126 127 128 129 130 131 |
# File 'lib/webgen/path.rb', line 123 def ==(other) if other.kind_of?(Path) other.path == @path elsif other.kind_of?(String) other == @path else false end end |
#=~(pattern) ⇒ Object
Return true if the localized path matches the given pattern. For information on which patterns are supported, have a look at the documentation of File.fnmatch.
136 137 138 |
# File 'lib/webgen/path.rb', line 136 def =~(pattern) File.fnmatch(pattern, File.join(@directory, lcn), File::FNM_DOTMATCH|File::FNM_CASEFOLD|File::FNM_PATHNAME) end |
#changed? ⇒ Boolean
Has the content of this path changed since the last webgen run? This default implementation always returns true, a specialized sub class needs to override this behaviour!
83 84 85 |
# File 'lib/webgen/path.rb', line 83 def changed? true end |
#cn ⇒ Object
The canonical name created from the filename (created from cnbase and extension).
104 105 106 |
# File 'lib/webgen/path.rb', line 104 def cn @cnbase + (@ext.length > 0 ? '.' + @ext : '') end |
#dup ⇒ Object
Duplicate the path object.
88 89 90 91 92 |
# File 'lib/webgen/path.rb', line 88 def dup temp = super temp. = .dup temp end |
#hash ⇒ Object
Implemented sothat a Path looks like a String when used as key in a hash.
146 147 148 |
# File 'lib/webgen/path.rb', line 146 def hash @path.hash end |
#inspect ⇒ Object
:nodoc:
155 156 157 |
# File 'lib/webgen/path.rb', line 155 def inspect #:nodoc: "#<Path: #{@path}>" end |
#io ⇒ Object
The IO object associated with the path.
95 96 97 98 99 100 101 |
# File 'lib/webgen/path.rb', line 95 def io if @io @io else raise "No IO object defined for the path #{self}" end end |
#lcn ⇒ Object
The localized canonical name created from the filename.
118 119 120 |
# File 'lib/webgen/path.rb', line 118 def lcn self.class.lcn(cn, ['lang']) end |
#mount_at(mp, prefix = nil) ⇒ Object
Mount this path at the mount point mp optionally stripping prefix from the path and return the new path object.
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/webgen/path.rb', line 68 def mount_at(mp, prefix = nil) temp = dup temp.path = temp.path.sub(/^#{Regexp.escape(prefix.chomp("/"))}/, '') if prefix #" reanalyse = (@path == '/' || temp.path == '/') temp.path = File.join(mp, temp.path) if reanalyse temp.send(:analyse, temp.path) else temp.directory = File.join(File.dirname(temp.path), '/') end temp end |
#to_s ⇒ Object Also known as: to_str
:nodoc:
150 151 152 |
# File 'lib/webgen/path.rb', line 150 def to_s #:nodoc: @path.dup end |