Class: MasterView::MIO::StringMIO

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

Direct Known Subclasses

MTimeStringMIO

Instance Attribute Summary collapse

Attributes inherited from MIOBase

#pathname

Instance Method Summary collapse

Methods included from MasterViewIOIdenticalMixin

#identical?

Methods inherited from MIOBase

#full_pathname

Constructor Details

#initialize(path, string_hash, mtime = Time.new) ⇒ StringMIO

Returns a new instance of StringMIO.



274
275
276
277
278
# File 'lib/masterview/io.rb', line 274

def initialize(path, string_hash, mtime = Time.new)
  super(path)
  @string_hash = string_hash
  @mtime = mtime
end

Instance Attribute Details

#existObject

Returns the value of attribute exist.



271
272
273
# File 'lib/masterview/io.rb', line 271

def exist
  @exist
end

#mtimeObject (readonly)

Returns the value of attribute mtime.



272
273
274
# File 'lib/masterview/io.rb', line 272

def mtime
  @mtime
end

Instance Method Details

#exist?Boolean

Returns:

  • (Boolean)


300
301
302
# File 'lib/masterview/io.rb', line 300

def exist?
  @string_hash.has_key?(self.pathname.to_s)
end

#read(options = {}) ⇒ Object



280
281
282
# File 'lib/masterview/io.rb', line 280

def read(options = {})
  @string_hash[self.pathname.to_s]
end

#removeObject

remove - delete hash entry



305
306
307
# File 'lib/masterview/io.rb', line 305

def remove
  @string_hash.delete(self.pathname.to_s)
end

#write(content = nil, options = {}, &block) ⇒ Object



284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
# File 'lib/masterview/io.rb', line 284

def write(content = nil, options = {}, &block)
  written = false
  if block_given?
    sio = ::StringIO.new
    yield sio
    content = sio.string
  end

  if options[:force] || !self.identical?(content)
    @string_hash[self.pathname.to_s] = content
    @mtime = Time.now
    written = true
  end
  written
end