Class: GlooLang::Persist::DiscMech

Inherits:
Object
  • Object
show all
Defined in:
lib/gloo_lang/persist/disc_mech.rb

Instance Method Summary collapse

Constructor Details

#initialize(engine) ⇒ DiscMech

Set up a disc based file mechanism.



18
19
20
# File 'lib/gloo_lang/persist/disc_mech.rb', line 18

def initialize( engine )
  @engine = engine
end

Instance Method Details

#exist?(file) ⇒ Boolean

Check if a file exists.

Returns:

  • (Boolean)


44
45
46
# File 'lib/gloo_lang/persist/disc_mech.rb', line 44

def exist?( file )
  File.exist?( file )
end

#expand(name) ⇒ Object

Expand a single file path.



63
64
65
66
67
68
69
# File 'lib/gloo_lang/persist/disc_mech.rb', line 63

def expand( name )
  ext_path = File.expand_path( name )
  return [ ext_path ] if self.valid?( ext_path )

  full_name = "#{name}#{file_ext}"
  return [ File.join( @engine.settings.project_path, full_name ) ]
end

#file_extObject

Get the default file extention.



25
26
27
# File 'lib/gloo_lang/persist/disc_mech.rb', line 25

def file_ext
  return '.gloo'
end

#get_all_files_in(folder) ⇒ Object

Get all the gloo files in the folder (partial path).



32
33
34
35
36
37
38
39
# File 'lib/gloo_lang/persist/disc_mech.rb', line 32

def get_all_files_in( folder )
  pns = []
  dir = File.join( @engine.settings.project_path, folder )
  Dir.glob( "#{dir}*.gloo" ).each do |f|
    pns << f
  end
  return pns
end

#read(file) ⇒ Object

Read in the contents of a single file.



74
75
76
# File 'lib/gloo_lang/persist/disc_mech.rb', line 74

def read( file )
  return File.read( file )
end

#valid?(file) ⇒ Boolean

Check to see if the file is valid.

Returns:

  • (Boolean)


51
52
53
54
55
56
57
58
# File 'lib/gloo_lang/persist/disc_mech.rb', line 51

def valid?( file )
  return false unless file
  return false unless File.exist?( file )
  return false unless File.file?( file )
  return false unless file.end_with?( self.file_ext )

  return true
end

#write(pn, data) ⇒ Object

Write data to the file.



81
82
83
# File 'lib/gloo_lang/persist/disc_mech.rb', line 81

def write( pn, data )
  File.write( pn, data )
end