Class: Gloo::Persist::DiscMech
- Inherits:
-
Object
- Object
- Gloo::Persist::DiscMech
- Defined in:
- lib/gloo/persist/disc_mech.rb
Instance Method Summary collapse
-
#exist?(file) ⇒ Boolean
Check if a file exists.
-
#expand(name) ⇒ Object
Expand a single file path.
-
#file_ext ⇒ Object
Get the default file extention.
-
#get_all_files_in(folder) ⇒ Object
Get all the gloo files in the folder (partial path).
-
#initialize(engine) ⇒ DiscMech
constructor
Set up a disc based file mechanism.
-
#read(file) ⇒ Object
Read in the contents of a single file.
-
#valid?(file) ⇒ Boolean
Check to see if the file is valid.
-
#write(pn, data) ⇒ Object
Write data to the file.
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.
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 ( name ) ext_path = File.( 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_ext ⇒ Object
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.
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 |