Class: Informers::Utils::Hub::FileCache
- Inherits:
-
Object
- Object
- Informers::Utils::Hub::FileCache
- Defined in:
- lib/informers/utils/hub.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(path) ⇒ FileCache
constructor
A new instance of FileCache.
- #match(request) ⇒ Object
- #put(request, buffer) ⇒ Object
- #resolve_path(request) ⇒ Object
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
#path ⇒ Object (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 |