Class: Fog::Service
- Inherits:
-
Object
show all
- Defined in:
- lib/fog/core/service.rb
Direct Known Subclasses
AWS::CDN, AWS::Compute, AWS::ELB, AWS::IAM, AWS::SimpleDB, AWS::Storage, Bluebox::Compute, Brightbox::Compute, GoGrid::Compute, Google::Storage, Linode::Compute, Local::Storage, NewServers::Compute, Rackspace::CDN, Rackspace::Compute, Rackspace::Storage, Fog::Slicehost::Compute, Vcloud
Defined Under Namespace
Modules: Collections
Classes: Error, NotFound
Class Method Summary
collapse
Class Method Details
.collection(new_collection) ⇒ Object
88
89
90
|
# File 'lib/fog/core/service.rb', line 88
def collection(new_collection)
collections << new_collection
end
|
.collections ⇒ Object
92
93
94
|
# File 'lib/fog/core/service.rb', line 92
def collections
@collections ||= []
end
|
.inherited(child) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/fog/core/service.rb', line 21
def inherited(child)
child.class_eval <<-EOS, __FILE__, __LINE__
module Collections
include Fog::Service::Collections
def service
#{child}
end
end
def self.service
#{child}
end
EOS
end
|
.model(new_model) ⇒ Object
96
97
98
|
# File 'lib/fog/core/service.rb', line 96
def model(new_model)
models << new_model
end
|
.model_path(new_path) ⇒ Object
84
85
86
|
# File 'lib/fog/core/service.rb', line 84
def model_path(new_path)
@model_path = new_path
end
|
.models ⇒ Object
100
101
102
|
# File 'lib/fog/core/service.rb', line 100
def models
@models ||= []
end
|
.new(options = {}) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/fog/core/service.rb', line 41
def new(options={})
if Fog.bin
default_credentials = filter_parameters(Fog.credentials)
options = default_credentials.merge(options)
end
setup_requirements
if Fog.mocking?
service::Mock.send(:include, service::Collections)
service::Mock.new(options)
else
service::Real.send(:include, service::Collections)
service::Real.new(options)
end
end
|
.request(new_request) ⇒ Object
108
109
110
|
# File 'lib/fog/core/service.rb', line 108
def request(new_request)
requests << new_request
end
|
.request_path(new_path) ⇒ Object
104
105
106
|
# File 'lib/fog/core/service.rb', line 104
def request_path(new_path)
@request_path = new_path
end
|
.requests ⇒ Object
112
113
114
|
# File 'lib/fog/core/service.rb', line 112
def requests
@requests ||= []
end
|
.requirements ⇒ Object
37
38
39
|
# File 'lib/fog/core/service.rb', line 37
def requirements
declared_parameters_for :new, :required
end
|
.reset_data(keys = Mock.data.keys) ⇒ Object
116
117
118
|
# File 'lib/fog/core/service.rb', line 116
def reset_data(keys=Mock.data.keys)
Mock.reset_data(keys)
end
|
.setup_requirements ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/fog/core/service.rb', line 58
def setup_requirements
if superclass.respond_to?(:setup_requirements)
superclass.setup_requirements
end
@required ||= false
unless @required
for collection in collections
require [@model_path, collection].join('/')
constant = collection.to_s.split('_').map {|characters| characters[0...1].upcase << characters[1..-1]}.join('')
service::Collections.module_eval <<-EOS, __FILE__, __LINE__
def #{collection}(attributes = {})
#{service}::#{constant}.new({:connection => self}.merge(attributes))
end
EOS
end
for model in models
require [@model_path, model].join('/')
end
for request in requests
require [@request_path, request].join('/')
end
@required = true
end
end
|