Class: Amp::DelayedOpener
Instance Attribute Summary collapse
-
#default ⇒ Object
Returns the value of attribute default.
Instance Method Summary collapse
-
#initialize(realopener, owner) ⇒ DelayedOpener
constructor
Initializes the delayed opener, needing the real deal, and the owner of the delayed opener.
-
#open(name, mode = "r") ⇒ Object
Specialized opener that will fake writing when asked to.
Constructor Details
#initialize(realopener, owner) ⇒ DelayedOpener
Initializes the delayed opener, needing the real deal, and the owner of the delayed opener.
116 117 118 |
# File 'lib/amp/revlogs/changelog.rb', line 116 def initialize(realopener, owner) @real_opener, @owner = realopener, owner end |
Instance Attribute Details
#default ⇒ Object
Returns the value of attribute default.
105 106 107 |
# File 'lib/amp/revlogs/changelog.rb', line 105 def default @default end |
Instance Method Details
#open(name, mode = "r") ⇒ Object
Specialized opener that will fake writing when asked to. We need to know who our owner is and we need a real opener so we can actually open files. The DelayedOpener doesn’t know how to do real IO.
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/amp/revlogs/changelog.rb', line 124 def open(name, mode="r") fp = @real_opener.open(name, mode) return fp if name != @owner.index_file # Are we holding off on writing? if so, set up the file where we # writing pending data. if @owner.delay_count == 0 @owner.delay_name = File.amp_name(fp) mode.gsub!(/a/, 'w') if @owner.empty? return @real_opener.open(name+".a", mode) # See what I did there? end # FakeFileAppender = fake file so we don't do any real writing yet size = File.stat(@real_opener.join(name)).size ffa = FakeFileAppender.new(fp, @owner.delay_buffer, size) return ffa end |