Class: MonoFile

Inherits:
Object
  • Object
show all
Defined in:
lib/mono/base.rb

Class Method Summary collapse

Class Method Details

.exist?(path) ⇒ Boolean Also known as: exists?

Returns:

  • (Boolean)


102
103
104
# File 'lib/mono/base.rb', line 102

def self.exist?( path )
  ::File.exist?( expand_path( path ))
end

.expand_path(path) ⇒ Object Also known as: real_path

e.g. openfootball/austria etc.

expand 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.expand_path( path )
  "#{Mono.root}/#{path}"
end

.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. 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