Class: MonoFile
- Inherits:
-
Object
- Object
- MonoFile
- Defined in:
- lib/mono/base.rb
Class Method Summary collapse
- .exist?(path) ⇒ Boolean
-
.open(path, mode = 'r:utf-8', &block) ⇒ Object
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.
- .read_utf8(path) ⇒ Object
-
.real_path(path) ⇒ Object
e.g.
Class Method Details
.exist?(path) ⇒ Boolean
95 96 97 |
# File 'lib/mono/base.rb', line 95 def self.exist?( path ) ::File.exist?( real_path( path )) end |
.open(path, mode = 'r:utf-8', &block) ⇒ Object
path always relative to Mono.root
todo/fix: use File.( path, Mono.root ) - why? why not?
or always enfore "absolut" path e.g. do NOT allow ../ or ./ or such
103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/mono/base.rb', line 103 def self.open( path, mode='r:utf-8', &block ) full_path = real_path( path ) ## 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( full_path ) ) ## make sure path exists end ::File.open( full_path, mode ) do |file| block.call( file ) end end |
.read_utf8(path) ⇒ Object
115 116 117 |
# File 'lib/mono/base.rb', line 115 def self.read_utf8( path ) open( path, 'r:utf-8') { |file| file.read } end |
.real_path(path) ⇒ Object
e.g. openfootball/austria etc.
to to "real" absolute path
todo/check: assert name must be orgname,username/reponame
92 93 94 |
# File 'lib/mono/base.rb', line 92 def self.real_path( path ) "#{Mono.root}/#{path}" end |