Module: Fog::Mock
- Defined in:
- lib/fog/core/mock.rb
Class Method Summary collapse
- .delay ⇒ Object
- .delay=(new_delay) ⇒ Object
- .not_implemented(message = 'Contributions welcome!') ⇒ Object
- .random_base64(length) ⇒ Object
- .random_hex(length) ⇒ Object
- .random_ip(opts = {:version => :v4}) ⇒ Object
- .random_letters(length) ⇒ Object
- .random_letters_and_numbers(length) ⇒ Object
- .random_numbers(length) ⇒ Object
- .random_selection(characters, length) ⇒ Object
- .reset ⇒ Object
Class Method Details
.delay ⇒ Object
24 25 26 |
# File 'lib/fog/core/mock.rb', line 24 def self.delay @delay end |
.delay=(new_delay) ⇒ Object
28 29 30 31 |
# File 'lib/fog/core/mock.rb', line 28 def self.delay=(new_delay) raise ArgumentError, "delay must be non-negative" unless new_delay >= 0 @delay = new_delay end |
.not_implemented(message = 'Contributions welcome!') ⇒ Object
33 34 35 |
# File 'lib/fog/core/mock.rb', line 33 def self.not_implemented( = 'Contributions welcome!') raise Fog::Errors::MockNotImplemented.new() end |
.random_base64(length) ⇒ Object
53 54 55 56 57 58 |
# File 'lib/fog/core/mock.rb', line 53 def self.random_base64(length) random_selection( "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", length ) end |
.random_hex(length) ⇒ Object
60 61 62 63 |
# File 'lib/fog/core/mock.rb', line 60 def self.random_hex(length) max = ('f' * length).to_i(16) rand(max).to_s(16).rjust(length, '0') end |
.random_ip(opts = {:version => :v4}) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/fog/core/mock.rb', line 37 def self.random_ip(opts = {:version => :v4}) version = opts[:version] if version == :v6 bit_length = 128 family = Socket::AF_INET6 elsif version == :v4 bit_length = 32 family = Socket::AF_INET else raise ArgumentError, "Unknown IP version: #{version}" end seed = 1 + rand((2**bit_length)-1) IPAddr.new(seed, family).to_s end |
.random_letters(length) ⇒ Object
65 66 67 68 69 70 |
# File 'lib/fog/core/mock.rb', line 65 def self.random_letters(length) random_selection( 'abcdefghijklmnopqrstuvwxyz', length ) end |
.random_letters_and_numbers(length) ⇒ Object
77 78 79 80 81 82 |
# File 'lib/fog/core/mock.rb', line 77 def self.random_letters_and_numbers(length) random_selection( 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', length ) end |
.random_numbers(length) ⇒ Object
72 73 74 75 |
# File 'lib/fog/core/mock.rb', line 72 def self.random_numbers(length) max = ('9' * length).to_i rand(max).to_s end |
.random_selection(characters, length) ⇒ Object
84 85 86 87 88 89 90 91 |
# File 'lib/fog/core/mock.rb', line 84 def self.random_selection(characters, length) selection = '' length.times do position = rand(characters.length) selection << characters[position..position] end selection end |
.reset ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/fog/core/mock.rb', line 93 def self.reset mocked_services = [] Fog.constants.map do |x| x_const = Fog.const_get(x) x_const.respond_to?(:constants) && x_const.constants.map do |y| y_const = x_const.const_get(y) y_const.respond_to?(:constants) && y_const.constants.map do |z| if z.to_sym == :Mock mocked_services << y_const.const_get(z) end end end end for mocked_service in mocked_services next unless mocked_service.respond_to?(:reset) mocked_service.reset end end |