Class: Micdrop::FilesSourceRecord
- Inherits:
-
Object
- Object
- Micdrop::FilesSourceRecord
- Defined in:
- lib/micdrop/files_source.rb
Overview
Wrapper object to expose files as a source item
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(filename, binary_mode, file_opts) ⇒ FilesSourceRecord
constructor
A new instance of FilesSourceRecord.
Constructor Details
#initialize(filename, binary_mode, file_opts) ⇒ FilesSourceRecord
Returns a new instance of FilesSourceRecord.
48 49 50 51 52 53 |
# File 'lib/micdrop/files_source.rb', line 48 def initialize(filename, binary_mode, file_opts) @filename = filename @binary_mode = binary_mode @file_opts = file_opts @stat = nil end |
Instance Method Details
#[](key) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/micdrop/files_source.rb', line 55 def [](key) case key when :contents, :content File.open @filename, @binary_mode ? "rb" : "r", **@file_opts, &:read when :stream File.open @filename, @binary_mode ? "rb" : "r", **@file_opts when :path File.absolute_path @filename when :basename File.basename @filename when :filename @filename else @stat = File.stat(@filename) if @stat.nil? @stat.method(key).call end end |