Class: GlooLang::Persist::DiscMech
- Inherits:
-
Object
- Object
- GlooLang::Persist::DiscMech
- Defined in:
- lib/gloo_lang/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 |
# 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.
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 ( 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.
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.
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 |