Class: Smith::Commands::Push::FileReader

Inherits:
Object
  • Object
show all
Defined in:
lib/smith/commands/smithctl/push.rb

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ FileReader

Returns a new instance of FileReader.



99
100
101
# File 'lib/smith/commands/smithctl/push.rb', line 99

def initialize(file)
  @file = (file.is_a?(IO)) ? file : File.open(file)
end

Instance Method Details

#each(on_work, on_completed) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/smith/commands/smithctl/push.rb', line 103

def each(on_work, on_completed)
  on_done = proc do |message|
    line = @file.readline rescue nil
    if line
      class << on_done; alias :next :call; end
      on_work.call(line, on_done)
    else
      on_completed.call
    end
  end

  EM.next_tick(&on_done)
end