Sha256: 2ce6429729629724e3e5a63455658939be5e9dcf6c59533cf4b9645ad43cfa03

Contents?: true

Size: 1.2 KB

Versions: 19

Compression:

Stored size: 1.2 KB

Contents

module Fog

  @mocking = false

  def self.mock!
    @mocking = true
  end

  def self.mock?
    @mocking
  end

  def self.mocking?
    @mocking
  end

  module Mock

    @delay = 1
    def self.delay
      @delay
    end

    def self.delay=(new_delay)
      raise ArgumentError, "delay must be non-negative" unless new_delay >= 0
      @delay = new_delay
    end

    def self.not_implemented
      raise Fog::Errors::MockNotImplemented.new("Contributions welcome!")
    end

    def self.random_base64(length)
      random_selection(
        "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
        length
      )
    end

    def self.random_hex(length)
      max = ('f' * length).to_i(16)
      rand(max).to_s(16).rjust(length, '0')
    end

    def self.random_letters(length)
      random_selection(
        'abcdefghijklmnopqrstuvwxyz',
        length
      )
    end

    def self.random_numbers(length)
      max = ('9' * length).to_i
      rand(max).to_s
    end

    def self.random_selection(characters, length)
      selection = ''
      length.times do
        position = rand(characters.length)
        selection << characters[position..position]
      end
      selection
    end

  end

end

Version data entries

19 entries across 19 versions & 3 rubygems

Version Path
fog-0.8.1 lib/fog/core/mock.rb
fog-0.8.0 lib/fog/core/mock.rb
fog-0.7.2 lib/fog/core/mock.rb
fog-0.7.1 lib/fog/core/mock.rb
fog-0.7.0 lib/fog/core/mock.rb
bbcloud-0.11.2 lib/bbcloud/vendor/fog/lib/fog/core/mock.rb
bbcloud-0.11.1 lib/bbcloud/vendor/fog/lib/fog/core/mock.rb
bbcloud-0.11.0 lib/bbcloud/vendor/fog/lib/fog/core/mock.rb
fog-0.6.0 lib/fog/core/mock.rb
fog-0.5.3 lib/fog/core/mock.rb
fog-0.5.2 lib/fog/core/mock.rb
fog-0.5.1 lib/fog/core/mock.rb
fog-0.5.0 lib/fog/core/mock.rb
phpfog-fog-0.4.1.3 lib/fog/core/mock.rb
phpfog-fog-0.4.1.2 lib/fog/core/mock.rb
phpfog-fog-0.4.1.1 lib/fog/core/mock.rb
phpfog-fog-0.4.1 lib/fog/core/mock.rb
fog-0.4.1 lib/fog/core/mock.rb
fog-0.4.0 lib/fog/core/mock.rb