Sha256: 8489007e2293d3d90d688c199c43208a8d32daf49a492547a40cae87d4bf988a
Contents?: true
Size: 1001 Bytes
Versions: 2
Compression:
Stored size: 1001 Bytes
Contents
require 'base64' require 'rails' module BinaryFixtures::FixtureHelpers # The contents of a binary file, in a YAML-friendly format. # # @param [String] path the path of the binary file to be included, relative # to the Rails application's test/fixtures directory # @param [Hash] options optionally specify the current indent level # @option options [Integer] indent the number of spaces that the current line # in the YAML fixture file is indented by # @return [String] base64-encoded binary file contents def binary_file(path, options = {}) # The line with base64 data must be indented further than the current line. indent = ' ' * ((options[: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 end # module BinaryFixtures::FixtureHelpers
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
binary_fixtures-0.1.1 | lib/binary_fixtures/fixture_helpers.rb |
binary_fixtures-0.1.0 | lib/binary_fixtures/fixture_helpers.rb |