Sha256: cff44456445e14de252a82d72f08dbbc884d61e2886ccd97ad29937f4c18e3f5

Contents?: true

Size: 827 Bytes

Versions: 2

Compression:

Stored size: 827 Bytes

Contents

module Whisperer
  class Generator
    extend Helpers

    add_builder 'generate'

    attr_reader :record

    def initialize(record, name)
      @record, @name = record, name
    end

    def generate
      Preprocessors.process!(record)

      interaction = Convertors::Interaction.convert(record)

      self.uniq_cassette!

      cassette = VCR::Cassette.new("#{record.sub_path}/#{@name}")
      cassette.record_http_interaction(
        interaction
      )

      cassette.eject

      File.read(path_to_cassette)
    end

    protected
      def path_to_cassette
        "#{VCR.configuration.cassette_library_dir}/#{record.sub_path}/#{@name}.yml"
      end

      def uniq_cassette!
        if File.exists?(path_to_cassette)
          File.unlink(
            path_to_cassette
          )
        end
      end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
whisperer-0.0.2 lib/whisperer/generator.rb
whisperer-0.0.1 lib/whisperer/generator.rb