Class: MasterView::MIO::FileMIO

Inherits:
Pathname
  • Object
show all
Includes:
MasterViewIOIdenticalMixin
Defined in:
lib/masterview/io.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MasterViewIOIdenticalMixin

#identical?

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

#pathnameObject (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_pathnameObject



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(options = {})
  super()
end

#removeObject

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, options={}, &block)
  written = false
  if block_given?
    sio = ::StringIO.new
    yield sio
    content = sio.string
  end
  if options[:force] || !identical?(content)
    self.dirname.mkpath unless self.dirname.exist?
    self.open('w') do |io|
      io << content
    end
    written = true
  end
  written
end