Class: Gloo::Persist::DiscMech

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

Instance Method Summary collapse

Constructor Details

#initialize(engine) ⇒ DiscMech

Set up a disc based file mechanism.



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

def initialize( engine )
  @engine = engine
  @log = @engine.log
end

Instance Method Details

#exist?(file) ⇒ Boolean

Check if a file exists.

Returns:

  • (Boolean)


52
53
54
# File 'lib/gloo/persist/disc_mech.rb', line 52

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

#expand(name) ⇒ Object

Expand a single file path.



71
72
73
74
75
76
77
# File 'lib/gloo/persist/disc_mech.rb', line 71

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.



26
27
28
# File 'lib/gloo/persist/disc_mech.rb', line 26

def file_ext
  return '.gloo'
end

#get_all_files_in(folder) ⇒ Object

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



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/gloo/persist/disc_mech.rb', line 33

def get_all_files_in( folder )
  pns = []
  dir = File.join( @engine.settings.project_path, folder )

  unless Dir.exist?( dir )
    @log.debug "Folder does not exist in project: #{folder}"
    dir = File.join( @engine.settings.user_root, folder )
    @log.debug "Looking in gloo home? found == #{Dir.exist?( dir )}"
  end

  Dir.glob( "#{dir}*.gloo" ).each do |f|
    pns << f
  end
  return pns
end

#read(file) ⇒ Object

Read in the contents of a single file.



82
83
84
# File 'lib/gloo/persist/disc_mech.rb', line 82

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

#valid?(file) ⇒ Boolean

Check to see if the file is valid.

Returns:

  • (Boolean)


59
60
61
62
63
64
65
66
# File 'lib/gloo/persist/disc_mech.rb', line 59

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.



89
90
91
# File 'lib/gloo/persist/disc_mech.rb', line 89

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