Module: Fog::Service

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(other) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/fog/service.rb', line 4

def self.extended(other)
  super
  other.module_eval <<-EOS, __FILE__, __LINE__
    class Error < Fog::Errors::Error; end
    class NotFound < Fog::Errors::NotFound; end

    module Collections; end

    def self.new(options={})
      missing = []
      for requirement in requirements
        missing << requirement unless options[requirement]
      end
      unless missing.empty?
        if missing.length == 1
          raise(ArgumentError, [missing.first, "is required for this service"].join(' '))
        else
          raise(ArgumentError, [missing[0...-1].join(", "), 'and', missing[-1], 'are required for this service'].join(' '))
        end
      end

      unless @required
        for model in models
          require [@model_path, model].join('/')
        end
        for request in requests
          require [@request_path, request].join('/')
        end
        @required = true
      end

      instance = if Fog.mocking?
        Mock.new(options)
      else
        Real.new(options)
      end

      if self.respond_to?(:after_new)
        instance = self.after_new(instance, options)
      end
      instance
    end
  EOS
end

Instance Method Details

#model(new_model) ⇒ Object



53
54
55
# File 'lib/fog/service.rb', line 53

def model(new_model)
  models << new_model
end

#model_path(new_path) ⇒ Object



49
50
51
# File 'lib/fog/service.rb', line 49

def model_path(new_path)
  @model_path = new_path
end

#modelsObject



57
58
59
# File 'lib/fog/service.rb', line 57

def models
  @models ||= []
end

#request(new_request) ⇒ Object



65
66
67
# File 'lib/fog/service.rb', line 65

def request(new_request)
  requests << new_request
end

#request_path(new_path) ⇒ Object



61
62
63
# File 'lib/fog/service.rb', line 61

def request_path(new_path)
  @request_path = new_path
end

#requestsObject



69
70
71
# File 'lib/fog/service.rb', line 69

def requests
  @requests ||= []
end

#requirementsObject



77
78
79
# File 'lib/fog/service.rb', line 77

def requirements
  @requirements ||= []
end

#requires(*args) ⇒ Object



73
74
75
# File 'lib/fog/service.rb', line 73

def requires(*args)
  requirements.concat(args)
end

#reset_data(keys = Mock.data.keys) ⇒ Object



81
82
83
# File 'lib/fog/service.rb', line 81

def reset_data(keys=Mock.data.keys)
  Mock.reset_data(keys)
end