Sha256: c819f790f4138522e680a41048c0c27f8b9615ce577136ca631c9611491bd5d3

Contents?: true

Size: 633 Bytes

Versions: 3

Compression:

Stored size: 633 Bytes

Contents

module Imagery
  module Faking
    def self.included(base)
      base.extend ClassMethods
    end
      
    module ClassMethods
      def mode=(mode)
        @mode = mode
      end

      def mode
        @mode
      end

      def faked
        @omode, @mode = @mode, :fake
        yield
      ensure
        @mode = @omode
      end

      def real
        @omode, @mode = @mode, nil
        yield
      ensure
        @mode = @omode
      end
    end

    def save(io)
      return true if self.class.mode == :fake

      super
    end

    def delete
      return true if self.class.mode == :fake

      super
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
imagery-0.0.5 lib/imagery/faking.rb
imagery-0.0.4 lib/imagery/faking.rb
imagery-0.0.3 lib/imagery/faking.rb