Class: Informers::Utils::Hub::FileCache

Inherits:
Object
  • Object
show all
Defined in:
lib/informers/utils/hub.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ FileCache

Returns a new instance of FileCache.



73
74
75
# File 'lib/informers/utils/hub.rb', line 73

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



71
72
73
# File 'lib/informers/utils/hub.rb', line 71

def path
  @path
end

Instance Method Details

#match(request) ⇒ Object



77
78
79
80
81
82
# File 'lib/informers/utils/hub.rb', line 77

def match(request)
  file_path = resolve_path(request)
  file = FileResponse.new(file_path)

  file if file.exists
end

#put(request, buffer) ⇒ Object



84
85
86
87
88
89
90
91
92
93
# File 'lib/informers/utils/hub.rb', line 84

def put(request, buffer)
  output_path = resolve_path(request)

  begin
    FileUtils.mkdir_p(File.dirname(output_path))
    File.binwrite(output_path, buffer)
  rescue => e
    warn "An error occurred while writing the file to cache: #{e}"
  end
end

#resolve_path(request) ⇒ Object



95
96
97
# File 'lib/informers/utils/hub.rb', line 95

def resolve_path(request)
  File.join(@path, request)
end