class GcpDirectory::Listener

Watch for changes and send to API

Public Class Methods

listen() click to toggle source
# File lib/gcp_directory/listener.rb, line 44
def self.listen
  instance = GcpDirectory::Listener.new
  listener = Listen.to(GcpDirectory.directory) do |modified, added, removed|
    added.each { |file| instance.print(file) } if added
  end
  listener.start # not blocking
  $stderr.puts 'Press <CTRL-C> to stop listening'
  sleep
end
logger() click to toggle source
# File lib/gcp_directory/listener.rb, line 15
def self.logger
  GcpDirectory.logger
end
new() click to toggle source
# File lib/gcp_directory/listener.rb, line 7
def initialize
  @api = Printer.new
end

Public Instance Methods

logger() click to toggle source
# File lib/gcp_directory/listener.rb, line 11
def logger
  GcpDirectory.logger
end
print(added) click to toggle source
refresh_token_if_needed() click to toggle source
# File lib/gcp_directory/listener.rb, line 19
def refresh_token_if_needed
  if @last_refresh.nil? or @last_refresh < 59.minutes.ago
    GcpDirectory.refresh_token
    @last_refresh = Time.now
    @api = Printer.new
  end
end