Class: MasterView::MIO::FileMIO
- Includes:
- MasterViewIOIdenticalMixin
- Defined in:
- lib/masterview/io.rb
Instance Attribute Summary collapse
-
#pathname ⇒ Object
readonly
Returns the value of attribute pathname.
Instance Method Summary collapse
- #full_pathname ⇒ Object
-
#initialize(path, full_path = nil) ⇒ FileMIO
constructor
A new instance of FileMIO.
- #read(options = {}) ⇒ Object
-
#remove ⇒ Object
remove - delete file.
- #write(content = nil, options = {}, &block) ⇒ Object
Methods included from MasterViewIOIdenticalMixin
Methods inherited from Pathname
for_path, join, #path_no_ext, safe_concat
Constructor Details
#initialize(path, full_path = nil) ⇒ FileMIO
Returns a new instance of FileMIO.
232 233 234 235 236 |
# File 'lib/masterview/io.rb', line 232 def initialize(path, full_path=nil) full_path = path if full_path.nil? # ruby 1.8.5 Pathname.dirname calls self.class.new so we need to allow for single argument super(full_path) @pathname = Pathname.for_path(path) end |
Instance Attribute Details
#pathname ⇒ Object (readonly)
Returns the value of attribute pathname.
230 231 232 |
# File 'lib/masterview/io.rb', line 230 def pathname @pathname end |
Instance Method Details
#full_pathname ⇒ Object
238 239 240 |
# File 'lib/masterview/io.rb', line 238 def full_pathname self end |
#read(options = {}) ⇒ Object
242 243 244 |
# File 'lib/masterview/io.rb', line 242 def read( = {}) super() end |
#remove ⇒ Object
remove - delete file
264 265 266 |
# File 'lib/masterview/io.rb', line 264 def remove full_pathname.delete end |
#write(content = nil, options = {}, &block) ⇒ Object
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/masterview/io.rb', line 246 def write(content = nil, ={}, &block) written = false if block_given? sio = ::StringIO.new yield sio content = sio.string end if [:force] || !identical?(content) self.dirname.mkpath unless self.dirname.exist? self.open('w') do |io| io << content end written = true end written end |