Class: SmallCage::DocumentPath
- Inherits:
-
Object
- Object
- SmallCage::DocumentPath
- Defined in:
- lib/smallcage/document_path.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Class Method Summary collapse
- .add_smc_method(obj, value) ⇒ Object
- .create_with_uri(root, uri, base = nil) ⇒ Object
- .to_uri(root, path) ⇒ Object
Instance Method Summary collapse
-
#initialize(root, path) ⇒ DocumentPath
constructor
A new instance of DocumentPath.
- #outfile ⇒ Object
- #outuri ⇒ Object
- #smc? ⇒ Boolean
Constructor Details
#initialize(root, path) ⇒ DocumentPath
Returns a new instance of DocumentPath.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/smallcage/document_path.rb', line 5 def initialize(root, path) @root = Pathname.new(root).realpath @path = Pathname.new(path) if @path.exist? @path = @path.realpath else @path = @path.cleanpath end fail "Illegal path: #{ path.to_s }" if @path.to_s[0...@root.to_s.length] != @root.to_s if @path == @root @uri = '/' else @uri = @path.to_s[@root.to_s.length .. -1] end end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
3 4 5 |
# File 'lib/smallcage/document_path.rb', line 3 def path @path end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
3 4 5 |
# File 'lib/smallcage/document_path.rb', line 3 def root @root end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
3 4 5 |
# File 'lib/smallcage/document_path.rb', line 3 def uri @uri end |
Class Method Details
.add_smc_method(obj, value) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/smallcage/document_path.rb', line 52 def self.add_smc_method(obj, value) obj.instance_eval do @__smallcage ||= {} @__smallcage[:smc] = value end def obj.smc @__smallcage.nil? ? nil : @__smallcage[:smc] end obj end |
.create_with_uri(root, uri, base = nil) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/smallcage/document_path.rb', line 42 def self.create_with_uri(root, uri, base = nil) base ||= root if uri[0, 1] == '/' path = root + uri[1..-1] # absolute URI else path = base + uri # relative URI end new(root, path) end |
Instance Method Details
#outfile ⇒ Object
28 29 30 31 |
# File 'lib/smallcage/document_path.rb', line 28 def outfile return nil unless smc? self.class.new(@root, @path.to_s[0 .. -5]) end |
#outuri ⇒ Object
33 34 35 36 |
# File 'lib/smallcage/document_path.rb', line 33 def outuri return nil unless smc? uri[0 .. -5] end |
#smc? ⇒ Boolean
24 25 26 |
# File 'lib/smallcage/document_path.rb', line 24 def smc? @path.extname == '.smc' end |