Module: BinaryFixtures::FixtureHelpers
- Included in:
- ActiveRecord::FixtureSet::RenderContext
- Defined in:
- lib/binary_fixtures/fixture_helpers.rb
Instance Method Summary collapse
-
#binary_file(path, options = {}) ⇒ String
The contents of a binary file, in a YAML-friendly format.
-
#binary_file_size(path) ⇒ Integer
The number of bytes in a binary file.
Instance Method Details
#binary_file(path, options = {}) ⇒ String
The contents of a binary file, in a YAML-friendly format.
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/binary_fixtures/fixture_helpers.rb', line 14 def binary_file(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').join(path) binary_data = File.binread file_path base64_data = Base64.encode64 binary_data base64_data.gsub! "\n", "\n#{indent}" base64_data.strip! "!!binary |\n#{indent}#{base64_data}" end |
#binary_file_size(path) ⇒ Integer
The number of bytes in a binary file.
32 33 34 35 |
# File 'lib/binary_fixtures/fixture_helpers.rb', line 32 def binary_file_size(path) file_path = Rails.root.join('test/fixtures').join(path) File.stat(file_path).size end |