Module: Fog::Mock

Defined in:
lib/fog/core/mock.rb

Class Method Summary collapse

Class Method Details

.delayObject



20
21
22
# File 'lib/fog/core/mock.rb', line 20

def self.delay
  @delay
end

.delay=(new_delay) ⇒ Object

Raises:

  • (ArgumentError)


24
25
26
27
# File 'lib/fog/core/mock.rb', line 24

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

.not_implementedObject



29
30
31
# File 'lib/fog/core/mock.rb', line 29

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

.random_base64(length) ⇒ Object



33
34
35
36
37
38
# File 'lib/fog/core/mock.rb', line 33

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

.random_hex(length) ⇒ Object



40
41
42
43
# File 'lib/fog/core/mock.rb', line 40

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

.random_letters(length) ⇒ Object



45
46
47
48
49
50
# File 'lib/fog/core/mock.rb', line 45

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

.random_numbers(length) ⇒ Object



52
53
54
55
# File 'lib/fog/core/mock.rb', line 52

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

.random_selection(characters, length) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/fog/core/mock.rb', line 57

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