class Monopath
todo/check:
use as shared Mono/nomen/resource or such shared base class for Mononame & Monopath - why? why not?
Monoloc (for location) Monores (for resource) Mono__ ??
name components:
- better name for path? - use filepath, relpath, ...
Attributes
name[R]
note: org and name AND path for now required
- make name path optional too - why? why not?!!!
org[R]
note: org and name AND path for now required
- make name path optional too - why? why not?!!!
path[R]
note: org and name AND path for now required
- make name path optional too - why? why not?!!!
Public Class Methods
exist?( line )
click to toggle source
some File-like convenience helpers
e.g. File.exist? => Monopath.exist? File.open => Monopath.open( ... ) { block } etc.
# File lib/monofile/mononame.rb, line 154 def self.exist?( line ) File.exist?( real_path( line ) ) end
new( org, name, path )
click to toggle source
# File lib/monofile/mononame.rb, line 127 def initialize( org, name, path ) ## support/check for empty path too - why? why not? if org.is_a?(String) && name.is_a?(String) && path.is_a?(String) ## assume [org, name, path?] ## note: for now assumes proper formatted strings ## e.g. no leading @ or combined @hello/text in org ## or name or such ## - use parse/norm_name here too - why? why not? @org = org @name = name @path = path else raise ArgumentError, "[Monopath] expected three strings (org, name, path); got >#{org}< of type #{org.class.name}, >#{name}< of type #{name.class.name}, >#{path}< of type #{path.class.name}" end end
open( line, mode='r:utf-8', &block )
click to toggle source
path always relative to Mono.root
todo/fix: use File.expand_path( path, Mono.root ) - why? why not? or always enfore "absolut" path e.g. do NOT allow ../ or ./ or such
# File lib/monofile/mononame.rb, line 162 def self.open( line, mode='r:utf-8', &block ) path = real_path( line ) ## make sure path exists if we open for writing/appending - why? why not? if mode[0] == 'w' || mode[0] == 'a' FileUtils.mkdir_p( File.dirname( path ) ) ## make sure path exists end File.open( path, mode ) do |file| block.call( file ) end end
parse( line )
click to toggle source
# File lib/monofile/mononame.rb, line 108 def self.parse( line ) values = Mono.parse_name( line ) raise ArgumentError, "[Monopath] expected three parts (org/name/path); got #{values.pretty_inspect}" if values.size != 3 new( *values ) end
read_utf8( line )
click to toggle source
# File lib/monofile/mononame.rb, line 174 def self.read_utf8( line ) open( line, 'r:utf-8') { |file| file.read } end
real_path( line )
click to toggle source
# File lib/monofile/mononame.rb, line 114 def self.real_path( line ) monopath = parse( line ) monopath.real_path end
Also aliased as: realpath
Public Instance Methods
real_path()
click to toggle source
# File lib/monofile/mononame.rb, line 147 def real_path() "#{Mono.root}/#{to_path}"; end
Also aliased as: realpath
to_path()
click to toggle source
# File lib/monofile/mononame.rb, line 144 def to_path() "#{@org}/#{@name}/#{@path}"; end
to_s()
click to toggle source
# File lib/monofile/mononame.rb, line 145 def to_s() "@#{to_path}"; end