Module: GhostReader::Util

Defined in:
lib/ghost_reader/util.rb

Class Method Summary collapse

Class Method Details

.configObject



34
35
36
# File 'lib/ghost_reader/util.rb', line 34

def config
  YAML.load(File.read(config_file))
end

.config_fileObject



26
27
28
# File 'lib/ghost_reader/util.rb', line 26

def config_file
  File.join(::Rails.root, 'config', 'ghost_reader.yml')
end

.passenger_restart!Object



30
31
32
# File 'lib/ghost_reader/util.rb', line 30

def passenger_restart!
  FileUtils.touch(File.join(::Rails.root, 'tmp', 'restart.txt'))
end

.poll(headers = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/ghost_reader/util.rb', line 8

def poll(headers={})
  return unless File.exist?(config_file)
  headers['If-Modified-Since'] = File.mtime(translation_file) if File.exist?(translation_file)
  headers.reverse_merge! :method => :get
  excon = Excon.new(config['static'])
  response = excon.request(headers)
  if response.status == 200
    translation_file response.body
    passenger_restart!
  end
end

.translation_file(content = nil) ⇒ Object



20
21
22
23
24
# File 'lib/ghost_reader/util.rb', line 20

def translation_file(content=nil)
  path = File.join(::Rails.root, 'config', 'locales', 'ghost_reader.yml')
  return path if content.nil?
  File.open(path, 'w') { |f| f.puts content }
end