Commit 0df8987d authored by Praveen Arimbrathodiyil's avatar Praveen Arimbrathodiyil
Browse files

Imported Upstream version 1.24.0

parent f2088a55
......@@ -9,7 +9,6 @@ rvm:
- 1.9.2
- 1.9.3
- 2.0.0
- 2.1.0
- jruby-18mode
- jruby-19mode
- jruby-head
......@@ -53,7 +52,4 @@ notifications:
- "[#%{build_number}] %{compare_url}"
on_success: always
on_failure: always
use_notice: false
before_install:
- gem update --system # todo: workaround for https://github.com/rubygems/rubygems/pull/763
use_notice: false
\ No newline at end of file
......@@ -2,8 +2,11 @@
* Chris Johnson <wchrisjohnson@gmail.com>
* Dominic Cleal <dcleal@redhat.com>
* Evan Light <evan@tripledogdare.net>
* Mike Hagedorn <mike@silverchairsolutions.com>
* Naoto TAKAHASHI <tnaoto@gmail.com>
* Paul Thornthwaite <paul@brightbox.co.uk>
* Paul Thornthwaite <tokengeek@gmail.com>
* Paulo Henrique Lopes Ribeiro <plribeiro3000@gmail.com>
* Wesley Beary <geemus+github@gmail.com>
* geemus <geemus@gmail.com>
* mountkin <moutkin@gmail.com>
\ No newline at end of file
......@@ -2,6 +2,7 @@ source "https://rubygems.org"
gem 'nokogiri', '~>1.5.11'
gem 'mime-types', '~>1.16'
gem 'rest-client', '~> 1.6.7'
group :development, :test do
gem 'rake', '~> 10.1.0'
......
require 'bundler/setup'
task :travis => ['test:travis', 'coveralls_push_workaround']
task :default => [:test]
require "rake/testtask"
Rake::TestTask.new do |t|
t.libs << "lib"
t.libs << "spec"
t.pattern = "spec/**/*_spec.rb"
end
namespace :test do
task :travis do
mock = 'true' || ENV['FOG_MOCK']
task :travis do
# jruby coveralls causes an OOM in travis
ENV['COVERAGE'] = 'false' if RUBY_PLATFORM == 'java'
sh("export FOG_MOCK=#{mock} && rake")
end
end
sh("export FOG_MOCK=#{mock} && rake")
#require "tasks/changelog_task"
#Fog::Rake::ChangelogTask.new
task :coveralls_push_workaround do
use_coveralls = (Gem::Version.new(RUBY_VERSION) > Gem::Version.new('1.9.2'))
if (ENV['COVERAGE'] != 'false') && use_coveralls
if ENV['COVERAGE']
require 'coveralls/rake/task'
Coveralls::RakeTask.new
Rake::Task["coveralls:push"].invoke
end
end
end
\ No newline at end of file
1.24.0 08/26/2014
==========================================================
fixes for defaulting attributes
add method for getting all attributes
add methods for associations
add all_attributes, all_associations and all_associations_and_attributes helper methods
remove no-longer-needed gem update on travis
add all_values
fixes to avoid path conflicts with fog/fog
1.23.0 07/16/2014
==========================================================
attribute whitelisting
abstract out stringify for possible reuse
more specific naming
reorg
add path_prefix
fix time conversion to work with XMLRPC
add more specific per-type attribute tests
lock down rest-client for 1.8.7
allow namespace flipflop for dns
fix identity lookup
better default attribute value setting
bump excon
1.22.0 04/17/2014 1c086852e40e4c1ad7ed138834e4a1505ddb1416
==========================================================
attribute whitelisting
abstract out stringify for possible reuse
more specific naming
reorg
add path_prefix
fix time conversion to work with XMLRPC
add more specific per-type attribute tests
lock down rest-client for 1.8.7
allow namespace flipflop for dns
fix identity lookup
better default attribute value setting
bump excon
1.22.0 04/17/2014 1c086852e40e4c1ad7ed138834e4a1505ddb1416
==========================================================
tests/cleanup/fixes
1.21.1 03/18/2014 3a803405ba60ded421f4bd14677cd3c76cb7e6ab
==========================================================
......
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'fog/version'
require 'fog/core/version'
Gem::Specification.new do |spec|
spec.name = "fog-core"
......@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]
spec.add_dependency('builder')
spec.add_dependency('excon', '~>0.33')
spec.add_dependency('excon', '~>0.38')
spec.add_dependency('formatador', '~>0.2')
spec.add_dependency('mime-types')
spec.add_dependency('net-scp', '~>1.1')
......
......@@ -11,8 +11,22 @@ require 'timeout'
require 'ipaddr'
# internal core dependencies
require "fog/version"
require "fog/core/version"
require 'fog/core/attributes'
require 'fog/core/attributes/default'
require 'fog/core/attributes/array'
require 'fog/core/attributes/boolean'
require 'fog/core/attributes/float'
require 'fog/core/attributes/integer'
require 'fog/core/attributes/string'
require 'fog/core/attributes/time'
require 'fog/core/attributes/timestamp'
require 'fog/core/associations/default'
require 'fog/core/associations/many_identities'
require 'fog/core/associations/many_models'
require 'fog/core/associations/one_model'
require 'fog/core/associations/one_identity'
require 'fog/core/collection'
require 'fog/core/connection'
require 'fog/core/credentials'
......@@ -32,6 +46,8 @@ require 'fog/core/utils'
require 'fog/core/wait_for'
require 'fog/core/wait_for_defaults'
require 'fog/core/uuid'
require 'fog/core/stringify_keys'
require 'fog/core/whitelist_keys'
# service wrappers
require 'fog/account'
......
module Fog
module Associations
class Default
attr_reader :model, :name
def initialize(model, name, collection_name)
@model = model
@name = name
model.associations[name] = collection_name
create_setter
create_getter
end
end
end
end
\ No newline at end of file
module Fog
module Associations
class ManyIdentities < Default
def create_setter
model.class_eval <<-EOS, __FILE__, __LINE__
def #{name}=(new_#{name})
associations[:#{name}] = Array(new_#{name}).map do |association|
association.respond_to?(:identity) ? association.identity : association
end
end
EOS
end
def create_getter
model.class_eval <<-EOS, __FILE__, __LINE__
def #{name}
return [] if associations[:#{name}].nil?
Array(associations[:#{name}]).map do |association|
service.send(self.class.associations[:#{name}]).get(association)
end
end
EOS
end
end
end
end
\ No newline at end of file
module Fog
module Associations
class ManyModels < Default
def create_setter
model.class_eval <<-EOS, __FILE__, __LINE__
def #{name}=(new_#{name})
associations[:#{name}] = Array(new_#{name})
end
EOS
end
def create_getter
model.class_eval <<-EOS, __FILE__, __LINE__
def #{name}
Array(associations[:#{name}])
end
EOS
end
end
end
end
\ No newline at end of file
module Fog
module Associations
class OneIdentity < Default
def create_setter
model.class_eval <<-EOS, __FILE__, __LINE__
def #{name}=(new_#{name})
associations[:#{name}] = new_#{name}.respond_to?(:identity) ? new_#{name}.identity : new_#{name}
end
EOS
end
def create_getter
model.class_eval <<-EOS, __FILE__, __LINE__
def #{name}
return nil if associations[:#{name}].nil?
service.send(self.class.associations[:#{name}]).get(associations[:#{name}])
end
EOS
end
end
end
end
\ No newline at end of file
module Fog
module Associations
class OneModel < Default
def create_setter
model.class_eval <<-EOS, __FILE__, __LINE__
def #{name}=(new_#{name})
associations[:#{name}] = new_#{name}
end
EOS
end
def create_getter
model.class_eval <<-EOS, __FILE__, __LINE__
def #{name}
associations[:#{name}]
end
EOS
end
end
end
end
\ No newline at end of file
......@@ -10,98 +10,37 @@ module Fog
@aliases ||= {}
end
def associations
@associations ||= {}
end
def attributes
@attributes ||= []
end
def default_values
@default_values ||= {}
end
def attribute(name, options = {})
class_eval <<-EOS, __FILE__, __LINE__
def #{name}
attributes[:#{name}]
end
EOS
case options[:type]
when :boolean
class_eval <<-EOS, __FILE__, __LINE__
def #{name}=(new_#{name})
attributes[:#{name}] = case new_#{name}
when true,'true'
true
when false,'false'
false
end
end
EOS
when :float
class_eval <<-EOS, __FILE__, __LINE__
def #{name}=(new_#{name})
attributes[:#{name}] = new_#{name}.to_f
end
EOS
when :integer
class_eval <<-EOS, __FILE__, __LINE__
def #{name}=(new_#{name})
attributes[:#{name}] = new_#{name}.to_i
end
EOS
when :string
class_eval <<-EOS, __FILE__, __LINE__
def #{name}=(new_#{name})
attributes[:#{name}] = new_#{name}.to_s
end
EOS
when :time
class_eval <<-EOS, __FILE__, __LINE__
def #{name}=(new_#{name})
attributes[:#{name}] = if new_#{name}.nil? || new_#{name} == "" || new_#{name}.is_a?(Time)
new_#{name}
else
Time.parse(new_#{name})
end
end
EOS
when :timestamp
class_eval <<-EOS, __FILE__, __LINE__
def #{name}=(new_#{name})
attributes[:#{name}] = Time.at(new_#{name}.to_i)
end
EOS
when :array
class_eval <<-EOS, __FILE__, __LINE__
def #{name}=(new_#{name})
attributes[:#{name}] = [*new_#{name}]
end
EOS
else
if squash = options[:squash]
class_eval <<-EOS, __FILE__, __LINE__
def #{name}=(new_data)
if new_data.is_a?(Hash)
if new_data.has_key?(:'#{squash}')
attributes[:#{name}] = new_data[:'#{squash}']
elsif new_data.has_key?("#{squash}")
attributes[:#{name}] = new_data["#{squash}"]
else
attributes[:#{name}] = [ new_data ]
end
else
attributes[:#{name}] = new_data
end
end
EOS
else
class_eval <<-EOS, __FILE__, __LINE__
def #{name}=(new_#{name})
attributes[:#{name}] = new_#{name}
end
EOS
end
end
@attributes ||= []
@attributes |= [name]
for new_alias in [*options[:aliases]]
aliases[new_alias] = name
end
type = options.fetch(:type, 'default').to_s.capitalize
Fog::Attributes::const_get(type).new(self, name, options)
end
def has_one(name, collection_name)
Fog::Associations::OneModel.new(self, name, collection_name)
end
def has_many(name, collection_name)
Fog::Associations::ManyModels.new(self, name, collection_name)
end
def has_one_identity(name, collection_name)
Fog::Associations::OneIdentity.new(self, name, collection_name)
end
def has_many_identities(name, collection_name)
Fog::Associations::ManyIdentities.new(self, name, collection_name)
end
def identity(name, options = {})
......@@ -129,6 +68,28 @@ module Fog
@attributes ||= {}
end
def associations
@associations ||= {}
end
def all_attributes
self.class.attributes.inject({}) do |hash, attribute|
hash[attribute] = send(attribute)
hash
end
end
def all_associations
self.class.associations.keys.inject({}) do |hash, association|
hash[association] = associations[association] || send(association)
hash
end
end
def all_associations_and_attributes
all_attributes.merge(all_associations)
end
def dup
copy = super
copy.dup_attributes!
......
module Fog
module Attributes
class Array < Default
def create_setter
model.class_eval <<-EOS, __FILE__, __LINE__
def #{name}=(new_#{name})
attributes[:#{name}] = Array(new_#{name})
end
EOS
end
def create_getter
model.class_eval <<-EOS, __FILE__, __LINE__
def #{name}
Array(attributes[:#{name}])
end
EOS
end
end
end
end
\ No newline at end of file
module Fog
module Attributes
class Boolean < Default
def create_setter
model.class_eval <<-EOS, __FILE__, __LINE__
def #{name}=(new_#{name})
attributes[:#{name}] = case new_#{name}
when true,'true'
true
when false,'false'
false
end
end
EOS
end
end
end
end
\ No newline at end of file
module Fog
module Attributes
class Default
attr_reader :model, :name, :squash, :aliases, :default
def initialize(model, name, options)
@model = model
@model.attributes << name
@name = name
@squash = options.fetch(:squash, false)
@aliases = options.fetch(:aliases, [])
@default = options[:default]
create_setter
create_getter
create_aliases
set_defaults
end
def create_setter
if squash
model.class_eval <<-EOS, __FILE__, __LINE__
def #{name}=(new_data)
if new_data.is_a?(Hash)
if new_data.has_key?(:'#{squash}')
attributes[:#{name}] = new_data[:'#{squash}']
elsif new_data.has_key?("#{squash}")
attributes[:#{name}] = new_data["#{squash}"]
else
attributes[:#{name}] = [ new_data ]
end
else
attributes[:#{name}] = new_data
end
end
EOS
else
model.class_eval <<-EOS, __FILE__, __LINE__
def #{name}=(new_#{name})
attributes[:#{name}] = new_#{name}
end
EOS
end
end
def create_getter
model.class_eval <<-EOS, __FILE__, __LINE__
def #{name}
return attributes[:#{name}] unless attributes[:#{name}].nil?
if !attributes.key?(:#{name}) && !self.class.default_values[:#{name}].nil? && !persisted?
return self.class.default_values[:#{name}]
end
attributes[:#{name}]
end
EOS
end
def create_aliases
Array(aliases).each do |alias_name|
model.aliases[alias_name] = name
end
end
def set_defaults
model.default_values[name] = default unless default.nil?
end
end
end
end
\ No newline at end of file
module Fog
module Attributes
class Float < Default
def create_setter
model.class_eval <<-EOS, __FILE__, __LINE__
def #{name}=(new_#{name})
attributes[:#{name}] = new_#{name}.to_f
end
EOS
end
end
end
end
\ No newline at end of file
module Fog
module Attributes
class Integer < Default
def create_setter
model.class_eval <<-EOS, __FILE__, __LINE__
def #{name}=(new_#{name})
attributes[:#{name}] = new_#{name}.to_i
end
EOS
end
end
end
end
\ No newline at end of file
module Fog
module Attributes
class String < Default
def create_setter
model.class_eval <<-EOS, __FILE__, __LINE__
def #{name}=(new_#{name})
attributes[:#{name}] = new_#{name}.to_s
end
EOS
end
end
end
end
\ No newline at end of file
module Fog
module Attributes
class Time < Default
def create_setter
model.class_eval <<-EOS, __FILE__, __LINE__
def #{name}=(new_#{name})
attributes[:#{name}] = if new_#{name}.nil? || new_#{name} == "" || new_#{name}.is_a?(::Time)
new_#{name}
elsif new_#{name}.respond_to?(:to_time)
new_#{name}.to_time
else
::Time.parse(new_#{name})
end
end
EOS
end
end
end