fog-core 1.21.1 → 1.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OTA5YWE2M2M1MTU2YzQxMzJkZWFhMTc2MmE4YThiYmE4MjlkMWY2MA==
4
+ YTNmYzY5ZmZiYjA4OTVkZWU2MTA0OTQ3ZmVmZmYxM2M0Y2UxY2ZkMA==
5
5
  data.tar.gz: !binary |-
6
- Mjc5ZGYxMDllM2FmNmIwNjNhZjNiOGQxZjM1ODFkYzM3YjI3NDkwYg==
6
+ MGJmMDEwODNmZjRiYjA5MTYzMmNkZjA3OTY4NTAzNzAzZGJkZjE0ZQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MDEzNGZmNzE3Zjg4NTZhZDNjMmE3YmIxZDQ1OTNiYTE3NDNjY2MzNjVjNjE4
10
- MTFiYzY0ZjA1ZmEzMTlhZjIzYTFmZmZhNDBlMDdjY2IxY2EwNGE0NjA5NTky
11
- MzJhMDcwOWY0ZmQ2NTIwZTNkZjIxYjc5NzgzMWJmYzVjYWE4Nzg=
9
+ NTNmYzVjYzdjMmJiN2NjMjU3ZmFmYTYxZGJiYTA1MTEzZjBmNWFmMWY3Zjg0
10
+ NDU0YTcxYWY5ZTU0ODViMGIwMTYyN2IzMWI4YWFlOTVhZjgyYjM5ODU0MTcx
11
+ ZTY2MGZkZTVmYmFlMDI4NmVlZGFkNWMxMmY1YTcyOWZhNjJlYTc=
12
12
  data.tar.gz: !binary |-
13
- NzFkYmI1MzUzNWQ0M2Y5OTZmMzgxOTU0NDRkMWU3MjMwODgyZDA2ODcyNjQ3
14
- YzNkMzNlZWI1MGI3NTFkYzUxNGVkZmQyNjZhOWI4NjM0NDkwZjVhOWFjODU1
15
- ZDMxNDllN2Y5YWUyZTkzMTVkOGMzZmRjMTBkMTdhNDY5NTgyYWY=
13
+ YTgyMTQ0MWQzOWI5NWM5OWYwNjcxZTE3NWExNWNhZmM1ODU0Y2RlNTNmMDlm
14
+ NGFjOThlNDNkNDNmMjA4YTlkNTU4NmU0YjRjNmE4Mzk0ZTExODYyODQzMzg4
15
+ OWVlZmQxNDRlM2U2YzViY2ZhOTA0MGY2YzUwOTFjNjFiZWQ2OWI=
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .#*
data/.travis.yml ADDED
@@ -0,0 +1,59 @@
1
+ language: ruby
2
+
3
+ gemfile:
4
+ - Gemfile
5
+ - Gemfile.1.8.7
6
+
7
+ rvm:
8
+ - 1.8.7
9
+ - 1.9.2
10
+ - 1.9.3
11
+ - 2.0.0
12
+ - 2.1.0
13
+ - jruby-18mode
14
+ - jruby-19mode
15
+ - jruby-head
16
+
17
+ script: bundle exec rake travis
18
+
19
+ matrix:
20
+ include:
21
+ - rvm: 2.1.0
22
+ gemfile: Gemfile
23
+ env: COVERAGE=true
24
+ exclude:
25
+ - rvm: 1.8.7
26
+ gemfile: Gemfile
27
+ - rvm: 1.9.2
28
+ gemfile: Gemfile.1.8.7
29
+ - rvm: 1.9.3
30
+ gemfile: Gemfile.1.8.7
31
+ - rvm: 2.0.0
32
+ gemfile: Gemfile.1.8.7
33
+ - rvm: 2.1.0
34
+ gemfile: Gemfile.1.8.7
35
+ - rvm: jruby-18mode
36
+ gemfile: Gemfile
37
+ - rvm: jruby-19mode
38
+ gemfile: Gemfile.1.8.7
39
+ - rvm: jruby-head
40
+ gemfile: Gemfile.1.8.7
41
+
42
+ allow_failures:
43
+ - rvm: jruby-head
44
+
45
+ notifications:
46
+ email: false
47
+ irc:
48
+ channels:
49
+ - "irc.freenode.org#ruby-fog"
50
+ template:
51
+ - "[#%{build_number}] %{message} %{build_url}"
52
+ - "[#%{build_number}] %{commit} on %{branch} by %{author}"
53
+ - "[#%{build_number}] %{compare_url}"
54
+ on_success: always
55
+ on_failure: always
56
+ use_notice: false
57
+
58
+ before_install:
59
+ - gem update --system # todo: workaround for https://github.com/rubygems/rubygems/pull/763
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,22 @@
1
+ ## Getting Involved
2
+
3
+ New contributors are always welcome, when it doubt please ask questions. We strive to be an open and welcoming community. Please be nice to one another.
4
+
5
+ ### Coding
6
+
7
+ * Pick a task:
8
+ * Offer feedback on open [pull requests](https://github.com/fog/fog-core/pulls).
9
+ * Review open [issues](https://github.com/fog/fog-core/issues) for things to help on.
10
+ * [Create an issue](https://github.com/fog/fog-core/issues/new) to start a discussion on additions or features.
11
+ * Fork the project, add your changes and tests to cover them in a topic branch.
12
+ * Commit your changes and rebase against `fog/fog-core` to ensure everything is up to date.
13
+ * [Submit a pull request](https://github.com/fog/fog-core/compare/)
14
+
15
+ ### Non-Coding
16
+
17
+ * Offer feedback on open [issues](https://github.com/fog/fog-core/issues).
18
+ * Write and help edit [documentation](https://github.com/fog/fog.github.com).
19
+ * Translate [documentation](https://github.com/fog/fog.github.com) in to other languages.
20
+ * Organize or volunteer at events.
21
+ * [Donate](https://www.gittip.com/geemus/)
22
+ * Discuss other ideas for contribution with [geemus](mailto:geemus+fog@gmail.com).
data/CONTRIBUTORS.md ADDED
@@ -0,0 +1,9 @@
1
+ * Anatol <anatol.pomozov@gmail.com>
2
+ * Chris Johnson <wchrisjohnson@gmail.com>
3
+ * Dominic Cleal <dcleal@redhat.com>
4
+ * Evan Light <evan@tripledogdare.net>
5
+ * Paul Thornthwaite <paul@brightbox.co.uk>
6
+ * Paul Thornthwaite <tokengeek@gmail.com>
7
+ * Wesley Beary <geemus+github@gmail.com>
8
+ * geemus <geemus@gmail.com>
9
+ * mountkin <moutkin@gmail.com>
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
data/Gemfile.1.8.7 ADDED
@@ -0,0 +1,12 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'nokogiri', '~>1.5.11'
4
+ gem 'mime-types', '~>1.16'
5
+
6
+ group :development, :test do
7
+ gem 'rake', '~> 10.1.0'
8
+ # This is here because gemspec doesn't support require: false
9
+ gem 'coveralls', :require => false
10
+ end
11
+
12
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 [CONTRIBUTORS.md](https://github.com/fog/fog/blob/master/CONTRIBUTORS.md)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Fog::Core
2
+
3
+ Shared classes and tests for fog providers and services.
4
+
5
+ [![Build Status](https://secure.travis-ci.org/fog/fog-core.png?branch=master)](http://travis-ci.org/fog/fog-core)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'fog-core'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install fog-core
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( http://github.com/<my-github-username>/fog-core/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,33 @@
1
+ require 'bundler/setup'
2
+
3
+ task :travis => ['test:travis', 'coveralls_push_workaround']
4
+ task :default => [:test]
5
+
6
+ require "rake/testtask"
7
+
8
+
9
+ Rake::TestTask.new do |t|
10
+ t.libs << "lib"
11
+ t.libs << "spec"
12
+ t.pattern = "spec/**/*_spec.rb"
13
+ end
14
+
15
+ namespace :test do
16
+ mock = 'true' || ENV['FOG_MOCK']
17
+ task :travis do
18
+ # jruby coveralls causes an OOM in travis
19
+ ENV['COVERAGE'] = 'false' if RUBY_PLATFORM == 'java'
20
+ sh("export FOG_MOCK=#{mock} && rake")
21
+ end
22
+ end
23
+
24
+ #require "tasks/changelog_task"
25
+ #Fog::Rake::ChangelogTask.new
26
+ task :coveralls_push_workaround do
27
+ use_coveralls = (Gem::Version.new(RUBY_VERSION) > Gem::Version.new('1.9.2'))
28
+ if (ENV['COVERAGE'] != 'false') && use_coveralls
29
+ require 'coveralls/rake/task'
30
+ Coveralls::RakeTask.new
31
+ Rake::Task["coveralls:push"].invoke
32
+ end
33
+ end
data/changelog.md ADDED
@@ -0,0 +1,7 @@
1
+ 1.21.1 03/18/2014 3a803405ba60ded421f4bd14677cd3c76cb7e6ab
2
+ ==========================================================
3
+
4
+ remove json/xml modules and code
5
+ add travis/coveralls
6
+ update from upstream
7
+ bump/loosen excon dependency
data/fog-core.gemspec ADDED
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fog/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fog-core"
8
+ spec.version = Fog::VERSION
9
+ spec.authors = ["Evan Light", "Wesley Beary"]
10
+ spec.email = ["evan@tripledogdare.net", "geemus@gmail.com"]
11
+ spec.summary = %q{Shared classes and tests for fog providers and services.}
12
+ spec.description = %q{Shared classes and tests for fog providers and services.}
13
+ spec.homepage = "https://github.com/fog/fog-core"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency('builder')
22
+ spec.add_dependency('excon', '~>0.33')
23
+ spec.add_dependency('formatador', '~>0.2')
24
+ spec.add_dependency('mime-types')
25
+ spec.add_dependency('net-scp', '~>1.1')
26
+ spec.add_dependency('net-ssh', '>=2.1.3')
27
+
28
+ spec.add_development_dependency('rake')
29
+ spec.add_development_dependency('yard')
30
+ spec.add_development_dependency('thor')
31
+ spec.add_development_dependency('minitest')
32
+ spec.add_development_dependency('minitest-stub-const')
33
+ spec.add_development_dependency('pry')
34
+ spec.add_development_dependency('coveralls')
35
+ end
data/lib/fog/compute.rb CHANGED
@@ -55,9 +55,14 @@ module Fog
55
55
  else
56
56
  if self.providers.include?(provider)
57
57
  require "fog/#{provider}/compute"
58
- return Fog::Compute.const_get(Fog.providers[provider]).new(attributes)
58
+ begin
59
+ Fog::Compute.const_get(Fog.providers[provider])
60
+ rescue
61
+ Fog::const_get(Fog.providers[provider])::Compute
62
+ end.new(attributes)
63
+ else
64
+ raise ArgumentError.new("#{provider} is not a recognized compute provider")
59
65
  end
60
- raise ArgumentError.new("#{provider} is not a recognized compute provider")
61
66
  end
62
67
  end
63
68
 
data/lib/fog/core.rb CHANGED
@@ -28,9 +28,9 @@ require 'fog/core/service'
28
28
  require 'fog/core/ssh'
29
29
  require 'fog/core/scp'
30
30
  require 'fog/core/time'
31
+ require 'fog/core/utils'
31
32
  require 'fog/core/wait_for'
32
33
  require 'fog/core/wait_for_defaults'
33
- require 'fog/core/class_from_string'
34
34
  require 'fog/core/uuid'
35
35
 
36
36
  # service wrappers
@@ -3,19 +3,49 @@ require 'yaml'
3
3
  module Fog
4
4
  require 'fog/core/deprecation'
5
5
 
6
+ # Sets the global configuration up from a Hash rather than using background loading from a file
7
+ #
8
+ # @example
9
+ # Fog.credentials = {
10
+ # :default => {
11
+ # :example_url => "https://example.com/"
12
+ # :example_username => "bob",
13
+ # :example_password => "obo"
14
+ # },
15
+ # :production => {
16
+ # :example_username => "bob",
17
+ # :example_password => "obo"
18
+ # }
19
+ # }
20
+ #
21
+ # @return [Hash] The newly assigned credentials
22
+ def self.credentials=(new_credentials)
23
+ @credentials = new_credentials
24
+ end
25
+
6
26
  # Assign a new credential to use from configuration file
7
- # @param [String, Symbol] new_credential name of new credential to use
8
- # @ return [Symbol] name of the new credential
27
+ #
28
+ # @param [String, Symbol] new_credential name of new credential to use
29
+ # @return [Symbol] name of the new credential
9
30
  def self.credential=(new_credential)
10
31
  @credentials = nil
11
32
  @credential = new_credential && new_credential.to_sym
12
33
  end
13
34
 
14
- # @return [String, Symbol] The credential to use in Fog
35
+ # This is the named credential from amongst the configuration file being used or +:default+
36
+ #
37
+ # @note This can be set using the +FOG_CREDENTIAL+ environment variable
38
+ #
39
+ # @return [Symbol] The credential to use in Fog
15
40
  def self.credential
16
41
  @credential ||= ( ENV["FOG_CREDENTIAL"] && ENV["FOG_CREDENTIAL"].to_sym ) || :default
17
42
  end
18
43
 
44
+ # This returns the path to the configuration file being used globally to look for sets of
45
+ # credentials
46
+ #
47
+ # @note This can be set using the +FOG_RC+ environment variable or defaults to +$HOME/.fog+
48
+ #
19
49
  # @return [String] The path for configuration_file
20
50
  def self.credentials_path
21
51
  @credential_path ||= begin
@@ -35,9 +65,9 @@ module Fog
35
65
  # @return [Hash] The credentials pulled from the configuration file
36
66
  # @raise [LoadError] Configuration unavailable in configuration file
37
67
  def self.credentials
38
- @credentials ||= begin
68
+ @credentials ||= begin
39
69
  if credentials_path && File.exists?(credentials_path)
40
- credentials = self.symbolize_credentials(YAML.load_file(credentials_path))
70
+ credentials = Fog::Core::Utils.prepare_service_settings(YAML.load_file(credentials_path))
41
71
  (credentials && credentials[credential]) || Fog::Errors.missing_credentials
42
72
  else
43
73
  {}
@@ -45,26 +75,15 @@ module Fog
45
75
  end
46
76
  end
47
77
 
48
- # @return [Hash] The newly assigned credentials
49
- def self.credentials=(new_credentials)
50
- @credentials = new_credentials
51
- end
52
-
78
+ # @deprecated Don't use!
79
+ # @param [Object] key
80
+ # @return [true] if key == :headers
53
81
  def self.symbolize_credential?(key)
54
82
  ![:headers].include?(key)
55
83
  end
56
84
 
57
- def self.symbolize_credentials(args)
58
- if args.is_a? Hash
59
- copy = Array.new
60
- args.each do |key, value|
61
- obj = symbolize_credential?(key) ? self.symbolize_credentials(value) : value
62
- copy.push(key.to_sym, obj)
63
- end
64
- Hash[*copy]
65
- else
66
- args
67
- end
85
+ # @deprecated Use {Fog::Core::Utils.prepare_service_settings} instead
86
+ def self.symbolize_credentials(hash)
87
+ Fog::Core::Utils.prepare_service_settings(hash)
68
88
  end
69
-
70
89
  end
@@ -12,12 +12,13 @@ module Fog
12
12
 
13
13
  def initialize(new_attributes = {})
14
14
  # TODO Remove compatibility with old connection option
15
- @service = new_attributes.delete(:service)
16
- if @service.nil? && new_attributes[:connection]
15
+ attribs = new_attributes.clone
16
+ @service = attribs.delete(:service)
17
+ if @service.nil? && attribs[:connection]
17
18
  Fog::Logger.deprecation("Passing :connection option is deprecated, use :service instead [light_black](#{caller.first})[/]")
18
- @service = new_attributes[:connection]
19
+ @service = attribs[:connection]
19
20
  end
20
- merge_attributes(new_attributes)
21
+ merge_attributes(attribs)
21
22
  end
22
23
 
23
24
  def inspect
@@ -1,11 +1,11 @@
1
- module Fog
1
+ require "fog/core/utils"
2
2
 
3
+ module Fog
3
4
  def self.services
4
5
  @services ||= {}
5
6
  end
6
7
 
7
8
  class Service
8
-
9
9
  class Error < Fog::Errors::Error; end
10
10
  class NotFound < Fog::Errors::NotFound; end
11
11
 
@@ -16,7 +16,6 @@ module Fog
16
16
  end
17
17
 
18
18
  module Collections
19
-
20
19
  def collections
21
20
  service.collections
22
21
  end
@@ -28,11 +27,9 @@ module Fog
28
27
  def requests
29
28
  service.requests
30
29
  end
31
-
32
30
  end
33
31
 
34
32
  class << self
35
-
36
33
  def inherited(child)
37
34
  child.class_eval <<-EOS, __FILE__, __LINE__
38
35
  class Error < Fog::Service::Error; end
@@ -52,27 +49,78 @@ module Fog
52
49
  EOS
53
50
  end
54
51
 
55
- def new(options={})
56
- options = Fog.symbolize_credentials(options)
57
- options = fetch_credentials(options).merge(options)
58
- validate_options(options)
59
- coerce_options(options)
52
+ # {Fog::Service} is (unfortunately) both a builder class and the subclass for any fog service.
53
+ #
54
+ # Creating a {new} instance using the builder will return either an instance of
55
+ # +Fog::<Service>::<Provider>::Real+ or +Fog::<Service>::<Provider>::Mock+ based on the value
56
+ # of {Fog.mock?} when the builder is used.
57
+ #
58
+ # Each provider can require or recognize different settings (often prefixed with the providers
59
+ # name). These settings map to keys in the +~/.fog+ file.
60
+ #
61
+ # Settings can be passed as either a Hash or an object that responds to +config_service?+ with
62
+ # +true+. This object will be passed through unchanged to the +Real+ or +Mock+ service that is
63
+ # created. It is up to providers to adapt services to use these config objects.
64
+ #
65
+ # @abstract Subclass and implement real or mock code
66
+ #
67
+ # @param [Hash,#config_service?] config
68
+ # Settings or an object used to build a service instance
69
+ # @option config [Hash] :headers
70
+ # Passed to the underlying {Fog::Core::Connection} unchanged
71
+ #
72
+ # @return [Fog::Service::Provider::Real] if created while mocking is disabled
73
+ # @return [Fog::Service::Provider::Mock] if created while mocking is enabled
74
+ # @raise [ArgumentError] if a setting required by the provider was not passed in
75
+ #
76
+ # @example Minimal options (dependent on ~/.fog)
77
+ # @service = Fog::Compute::Example.new # => <#Fog::Compute::Example::Real>
78
+ #
79
+ # @example Mocked service
80
+ # Fog.mock!
81
+ # @service = Fog::Compute::Example.new # => <#Fog::Compute::Example::Mock>
82
+ #
83
+ # @example Configured using many options (options merged into ~/.fog)
84
+ # @options = {
85
+ # :example_username => "fog",
86
+ # :example_password => "fog"
87
+ # }
88
+ # @service = Fog::Compute::Example.new(@options)
89
+ #
90
+ # @example Configured using external config object (~/.fog ignored completely)
91
+ # @config = Fog::Example::Config.new(...)
92
+ # @service = Fog::Compute::Example.new(@config)
93
+ #
94
+ def new(config = {})
95
+ if config.respond_to?(:config_service?) && config.config_service?
96
+ cleaned_settings = config
97
+ else
98
+ cleaned_settings = handle_settings(config)
99
+ end
60
100
  setup_requirements
61
101
 
102
+ svc = service
62
103
  if Fog.mocking?
63
- service::Mock.send(:include, service::Collections)
64
- service::Mock.new(options)
104
+ while svc != Fog::Service
105
+ service::Mock.send(:include, svc::Collections)
106
+ svc = svc.superclass
107
+ end
108
+ service::Mock.new(cleaned_settings)
65
109
  else
66
- service::Real.send(:include, service::Collections)
110
+ while svc != Fog::Service
111
+ service::Real.send(:include, svc::Collections)
112
+ svc = svc.superclass
113
+ end
67
114
  service::Real.send(:include, service::NoLeakInspector)
68
- service::Real.new(options)
115
+ service::Real.new(cleaned_settings)
69
116
  end
70
117
  end
71
118
 
119
+ # @deprecated
72
120
  def fetch_credentials(options)
73
121
  # attempt to load credentials from config file
74
122
  begin
75
- Fog.credentials.reject {|key, value| !(recognized | requirements).include?(key)}
123
+ Fog.credentials.reject { |key, value| !(recognized | requirements).include?(key) }
76
124
  rescue LoadError
77
125
  # if there are no configured credentials, do nothing
78
126
  {}
@@ -86,34 +134,14 @@ module Fog
86
134
 
87
135
  @required ||= false
88
136
  unless @required
89
- for collection in collections
90
- require [@model_path, collection].join('/')
91
- constant = collection.to_s.split('_').map {|characters| characters[0...1].upcase << characters[1..-1]}.join('')
92
- service::Collections.module_eval <<-EOS, __FILE__, __LINE__
93
- def #{collection}(attributes = {})
94
- #{service}::#{constant}.new({:service => self}.merge(attributes))
95
- end
96
- EOS
97
- end
98
- for model in models
99
- require [@model_path, model].join('/')
100
- end
101
- for request in requests
102
- require [@request_path, request].join('/')
103
- if service::Mock.method_defined?(request)
104
- mocked_requests << request
105
- else
106
- service::Mock.module_eval <<-EOS, __FILE__, __LINE__
107
- def #{request}(*args)
108
- Fog::Mock.not_implemented
109
- end
110
- EOS
111
- end
112
- end
137
+ require_models
138
+ require_collections_and_define
139
+ require_requests_and_mock
113
140
  @required = true
114
141
  end
115
142
  end
116
143
 
144
+ # @note This path is used to require model and collection files
117
145
  def model_path(new_path)
118
146
  @model_path = new_path
119
147
  end
@@ -204,6 +232,7 @@ module Fog
204
232
  end
205
233
  end
206
234
  missing = requirements - keys
235
+
207
236
  unless missing.empty?
208
237
  raise ArgumentError, "Missing required arguments: #{missing.join(', ')}"
209
238
  end
@@ -216,8 +245,66 @@ module Fog
216
245
  end
217
246
  end
218
247
 
219
- end
248
+ private
249
+
250
+ # This is the original way service settings were handled. Settings from +~/.fog+ were merged
251
+ # together with the passed options, keys are turned to symbols and coerced into Boolean or
252
+ # Fixnums.
253
+ #
254
+ # If the class has declared any required settings then {ArgumentError} will be raised.
255
+ #
256
+ # Any setting that is not whitelisted will cause a warning to be output.
257
+ #
258
+ def handle_settings(settings)
259
+ combined_settings = fetch_credentials(settings).merge(settings)
260
+ prepared_settings = Fog::Core::Utils.prepare_service_settings(combined_settings)
261
+ validate_options(prepared_settings)
262
+ coerce_options(prepared_settings)
263
+ end
264
+
265
+ # This will attempt to require all model files declared by the service using fog's DSL
266
+ def require_models
267
+ models.each do |model|
268
+ require File.join(@model_path, model.to_s)
269
+ end
270
+ end
271
+
272
+ def require_collections_and_define
273
+ collections.each do |collection|
274
+ require File.join(@model_path, collection.to_s)
275
+ constant = camel_case_collection_name(collection)
276
+ service::Collections.module_eval <<-EOS, __FILE__, __LINE__
277
+ def #{collection}(attributes = {})
278
+ #{service}::#{constant}.new({ :service => self }.merge(attributes))
279
+ end
280
+ EOS
281
+ end
282
+ end
283
+
284
+ # This converts names of collections from Symbols as defined in the DSL (+:database_server+)
285
+ # into CamelCase version (+DatabaseServer+) for metaprogramming skulduggery.
286
+ #
287
+ # @param [String,Symbol] collection The name of the collection broken with underscores
288
+ # @return [String] in camel case
289
+ def camel_case_collection_name(collection)
290
+ collection.to_s.split('_').map(&:capitalize).join
291
+ end
220
292
 
293
+ # This will attempt to require all request files declared in the service using fog's DSL
294
+ def require_requests_and_mock
295
+ requests.each do |request|
296
+ require File.join(@request_path, request.to_s)
297
+ if service::Mock.method_defined?(request)
298
+ mocked_requests << request
299
+ else
300
+ service::Mock.module_eval <<-EOS, __FILE__, __LINE__
301
+ def #{request}(*args)
302
+ Fog::Mock.not_implemented
303
+ end
304
+ EOS
305
+ end
306
+ end
307
+ end
308
+ end
221
309
  end
222
310
  end
223
-