class GitMQ::Consumer
Public Class Methods
new(storage:, name:, branch:)
click to toggle source
# File lib/consumer.rb, line 7 def initialize(storage:, name:, branch:) @storage = storage @branch = branch @name = name end
Public Instance Methods
branch_file()
click to toggle source
# File lib/consumer.rb, line 13 def branch_file @branch_file ||= File.join(@storage.path, 'refs', 'heads') end
consume(&block)
click to toggle source
# File lib/consumer.rb, line 17 def consume(&block) @block = block consume_commits listener.start end
stop()
click to toggle source
# File lib/consumer.rb, line 23 def stop listener.stop end
Private Instance Methods
consume_commits()
click to toggle source
# File lib/consumer.rb, line 35 def consume_commits commits = @storage.commits(@branch, @name) commits.each do |commit| @block.call commit.message @storage.tag(@name, commit) end end
listener()
click to toggle source
# File lib/consumer.rb, line 29 def listener @listener ||= Listen.to(branch_file, only: /#{Regexp.escape(@branch)}/) do consume_commits end end