Module: UIC::FileBacked
- Included in:
- Behavior, Effect, RenderPlugin, XMLFileBacked
- Defined in:
- lib/ruic/interfaces.rb
Overview
Supports classes that represent a file on disk (e.g. .uia
and .uip
).
Instance Attribute Summary collapse
-
#file ⇒ String
The absolute path to the underlying file.
-
#file_content ⇒ String
The content of the file.
Instance Method Summary collapse
-
#absolute_path(relative) ⇒ String
The full path resolved relative to this file.
-
#file_found? ⇒ Boolean
true
if the underlying file exists on disk. -
#filename ⇒ String
The name of the file (without any directories).
- #relative_path(path) ⇒ Object
-
#save! ⇒ true
Overwrite the associated file on disk with the
@file_content
of this class. -
#save_as(new_file) ⇒ Object
Save to the supplied file path.
Instance Attribute Details
#file ⇒ String
Returns the absolute path to the underlying file.
4 5 6 |
# File 'lib/ruic/interfaces.rb', line 4 def file @file end |
#file_content ⇒ String
Returns the content of the file.
7 8 9 |
# File 'lib/ruic/interfaces.rb', line 7 def file_content @file_content end |
Instance Method Details
#absolute_path(relative) ⇒ String
Returns the full path resolved relative to this file.
11 12 13 |
# File 'lib/ruic/interfaces.rb', line 11 def absolute_path( relative ) File.( relative.gsub('\\','/'), File.dirname(file) ) end |
#file_found? ⇒ Boolean
Returns true
if the underlying file exists on disk.
27 28 29 |
# File 'lib/ruic/interfaces.rb', line 27 def file_found? @file && File.exist?(@file) end |
#filename ⇒ String
Returns the name of the file (without any directories).
22 23 24 |
# File 'lib/ruic/interfaces.rb', line 22 def filename File.basename(file) end |
#relative_path(path) ⇒ Object
15 16 17 18 19 |
# File 'lib/ruic/interfaces.rb', line 15 def relative_path(path) my_dir = File.dirname(file) << "/" absolute_path(path).tap{ |s| s.slice!(my_dir) } end |
#save! ⇒ true
Overwrite the associated file on disk with the @file_content
of this class.
44 45 46 47 |
# File 'lib/ruic/interfaces.rb', line 44 def save! File.open(file,'w:utf-8'){ |f| f << @file_content } true end |
#save_as(new_file) ⇒ Object
Save to the supplied file path. Subsequent calls to #save! will save to the new file, not the original file name.
50 51 52 53 |
# File 'lib/ruic/interfaces.rb', line 50 def save_as(new_file) File.open(new_file,'w:utf-8'){ |f| f << @file_content } self.file = new_file end |