Class: MonoFile
- Inherits:
-
Object
- Object
- MonoFile
- Defined in:
- lib/mono/base.rb
Class Method Summary collapse
- .exist?(path) ⇒ Boolean (also: exists?)
-
.expand_path(path) ⇒ Object
(also: real_path)
e.g.
-
.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
Class Method Details
.exist?(path) ⇒ Boolean Also known as: exists?
102 103 104 |
# File 'lib/mono/base.rb', line 102 def self.exist?( path ) ::File.exist?( ( path )) end |
.expand_path(path) ⇒ Object Also known as: real_path
e.g. openfootball/austria etc.
to to "real" absolute path
todo/check: assert name must be orgname,username/reponame
99 100 101 |
# File 'lib/mono/base.rb', line 99 def self.( path ) "#{Mono.root}/#{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
118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/mono/base.rb', line 118 def self.open( path, mode='r:utf-8', &block ) full_path = "#{Mono.root}/#{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
130 131 132 |
# File 'lib/mono/base.rb', line 130 def self.read_utf8( path ) open( path, 'r:utf-8') { |file| file.read } end |