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.



107
108
109
# File 'lib/smith/commands/smithctl/push.rb', line 107

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

Instance Method Details

#each(on_work, on_completed) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/smith/commands/smithctl/push.rb', line 111

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