Module: FileBlobs::ActiveRecordFixtureSetExtensions
- Defined in:
- lib/file_blobs_rails/active_record_fixture_set_extensions.rb
Overview
Module mixed into ActiveRecord::FixtureSet.
Instance Method Summary collapse
-
#file_blob_data(path, options = {}) ⇒ String
The contents of a blob, in a YAML-friendly format.
-
#file_blob_id(path) ⇒ String
Computes the ID assigned to a blob.
-
#file_blob_size(path) ⇒ Integer
The number of bytes in a file.
Instance Method Details
#file_blob_data(path, options = {}) ⇒ String
The contents of a blob, in a YAML-friendly format.
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/file_blobs_rails/active_record_fixture_set_extensions.rb', line 30 def file_blob_data(path, = {}) # The line with base64 data must be indented further than the current line. indent = ' ' * (([:indent] || 2) + 2) file_path = Rails.root.join('test/fixtures'.freeze).join(path) blob_contents = File.binread file_path base64_data = Base64.encode64 blob_contents base64_data.gsub! "\n", "\n#{indent}" base64_data.strip! "!!binary |\n#{indent}#{base64_data}" end |
#file_blob_id(path) ⇒ String
Computes the ID assigned to a blob.
14 15 16 17 18 19 20 |
# File 'lib/file_blobs_rails/active_record_fixture_set_extensions.rb', line 14 def file_blob_id(path) file_path = Rails.root.join('test/fixtures'.freeze).join(path) blob_contents = File.binread file_path # This needs to be kept in sync with blob_model.rb. Base64.urlsafe_encode64(Digest::SHA256.digest(blob_contents)).inspect end |
#file_blob_size(path) ⇒ Integer
The number of bytes in a file.
48 49 50 51 |
# File 'lib/file_blobs_rails/active_record_fixture_set_extensions.rb', line 48 def file_blob_size(path) file_path = Rails.root.join('test/fixtures'.freeze).join(path) File.stat(file_path).size end |