fog 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,8 +7,8 @@ Gem::Specification.new do |s|
7
7
  ## If your rubyforge_project name is different, then edit it and comment out
8
8
  ## the sub! line in the Rakefile
9
9
  s.name = 'fog'
10
- s.version = '0.1.6'
11
- s.date = '2010-06-06'
10
+ s.version = '0.1.7'
11
+ s.date = '2010-06-07'
12
12
  s.rubyforge_project = 'fog'
13
13
 
14
14
  ## Make sure your summary is short. The description may be as long
@@ -71,6 +71,7 @@ Gem::Specification.new do |s|
71
71
  examples/bluebox_create.rb
72
72
  fog.gemspec
73
73
  lib/fog.rb
74
+ lib/fog/attributes.rb
74
75
  lib/fog/aws.rb
75
76
  lib/fog/aws/bin.rb
76
77
  lib/fog/aws/ec2.rb
data/lib/fog.rb CHANGED
@@ -18,6 +18,7 @@ $LOAD_PATH.unshift __DIR__ unless
18
18
  $LOAD_PATH.include?(__DIR__) ||
19
19
  $LOAD_PATH.include?(File.expand_path(__DIR__))
20
20
 
21
+ require 'fog/attributes'
21
22
  require 'fog/collection'
22
23
  require 'fog/connection'
23
24
  require 'fog/deprecation'
@@ -48,7 +49,7 @@ require 'fog/vcloud'
48
49
  module Fog
49
50
 
50
51
  unless const_defined?(:VERSION)
51
- VERSION = '0.1.6'
52
+ VERSION = '0.1.7'
52
53
  end
53
54
 
54
55
  module Mock
@@ -0,0 +1,96 @@
1
+ module Attributes
2
+ module ClassMethods
3
+
4
+ def _load(marshalled)
5
+ new(Marshal.load(marshalled))
6
+ end
7
+
8
+ def aliases
9
+ @aliases ||= {}
10
+ end
11
+
12
+ def attributes
13
+ @attributes ||= []
14
+ end
15
+
16
+ def attribute(name, other_names = [])
17
+ class_eval <<-EOS, __FILE__, __LINE__
18
+ attr_accessor :#{name}
19
+ EOS
20
+ @attributes ||= []
21
+ @attributes |= [name]
22
+ for other_name in [*other_names]
23
+ aliases[other_name] = name
24
+ end
25
+ end
26
+
27
+ def identity(name, other_names = [])
28
+ @identity = name
29
+ self.attribute(name, other_names)
30
+ end
31
+
32
+ end
33
+
34
+ module InstanceMethods
35
+
36
+ def _dump
37
+ Marshal.dump(attributes)
38
+ end
39
+
40
+ def attributes
41
+ attributes = {}
42
+ for attribute in self.class.attributes
43
+ attributes[attribute] = send("#{attribute}")
44
+ end
45
+ attributes
46
+ end
47
+
48
+ def identity
49
+ send(self.class.instance_variable_get('@identity'))
50
+ end
51
+
52
+ def identity=(new_identity)
53
+ send("#{self.class.instance_variable_get('@identity')}=", new_identity)
54
+ end
55
+
56
+ def merge_attributes(new_attributes = {})
57
+ for key, value in new_attributes
58
+ if aliased_key = self.class.aliases[key]
59
+ send("#{aliased_key}=", value)
60
+ else
61
+ send("#{key}=", value)
62
+ end
63
+ end
64
+ self
65
+ end
66
+
67
+ def new_record?
68
+ !identity
69
+ end
70
+
71
+ def requires(*args)
72
+ missing = []
73
+ for arg in [:connection] | args
74
+ missing << arg unless send("#{arg}")
75
+ end
76
+ unless missing.empty?
77
+ if missing.length == 1
78
+ raise(ArgumentError, "#{missing.first} is required for this operation")
79
+ else
80
+ raise(ArgumentError, "#{missing[0...-1].join(", ")} and #{missing[-1]} are required for this operation")
81
+ end
82
+ end
83
+ end
84
+
85
+ private
86
+
87
+ def remap_attributes(attributes, mapping)
88
+ for key, value in mapping
89
+ if attributes.key?(key)
90
+ attributes[value] = attributes.delete(key)
91
+ end
92
+ end
93
+ end
94
+
95
+ end
96
+ end
@@ -209,7 +209,7 @@ DATA
209
209
  end
210
210
  canonical_resource << "#{params[:path]}"
211
211
  canonical_resource << '?'
212
- for key in params[:query].keys
212
+ for key in (params[:query] || {}).keys
213
213
  if ['acl', 'location', 'logging', 'requestPayment', 'torrent', 'versions', 'versioning'].include?(key)
214
214
  canonical_resource << "#{key}&"
215
215
  end
@@ -1,6 +1,9 @@
1
1
  module Fog
2
2
  class Collection < Array
3
3
 
4
+ extend Attributes::ClassMethods
5
+ include Attributes::InstanceMethods
6
+
4
7
  Array.public_instance_methods(false).each do |method|
5
8
  class_eval <<-RUBY
6
9
  def #{method}(*args)
@@ -20,21 +23,6 @@ module Fog
20
23
  RUBY
21
24
  end
22
25
 
23
- def self._load(marshalled)
24
- new(Marshal.load(marshalled))
25
- end
26
-
27
- def self.attribute(name, other_names = [])
28
- class_eval <<-EOS, __FILE__, __LINE__
29
- attr_accessor :#{name}
30
- EOS
31
- @attributes ||= []
32
- @attributes |= [name]
33
- for other_name in [*other_names]
34
- aliases[other_name] = name
35
- end
36
- end
37
-
38
26
  def self.model(new_model=nil)
39
27
  if new_model == nil
40
28
  @model
@@ -43,33 +31,7 @@ module Fog
43
31
  end
44
32
  end
45
33
 
46
- def self.aliases
47
- @aliases ||= {}
48
- end
49
-
50
- def self.attributes
51
- @attributes ||= []
52
- end
53
-
54
- def _dump
55
- Marshal.dump(attributes)
56
- end
57
-
58
- def attributes
59
- attributes = {}
60
- for attribute in self.class.attributes
61
- attributes[attribute] = send("#{attribute}")
62
- end
63
- attributes
64
- end
65
-
66
- def connection=(new_connection)
67
- @connection = new_connection
68
- end
69
-
70
- def connection
71
- @connection
72
- end
34
+ attr_accessor :connection
73
35
 
74
36
  def create(attributes = {})
75
37
  object = new(attributes)
@@ -121,17 +83,6 @@ module Fog
121
83
  self.class.instance_variable_get('@model')
122
84
  end
123
85
 
124
- def merge_attributes(new_attributes = {})
125
- for key, value in new_attributes
126
- if aliased_key = self.class.aliases[key]
127
- send("#{aliased_key}=", value)
128
- else
129
- send("#{key}=", value)
130
- end
131
- end
132
- self
133
- end
134
-
135
86
  def new(attributes = {})
136
87
  model.new(
137
88
  attributes.merge(
@@ -161,13 +112,5 @@ module Fog
161
112
  end
162
113
  end
163
114
 
164
- def remap_attributes(attributes, mapping)
165
- for key, value in mapping
166
- if attributes.key?(key)
167
- attributes[value] = attributes.delete(key)
168
- end
169
- end
170
- end
171
-
172
115
  end
173
116
  end
@@ -1,60 +1,15 @@
1
1
  module Fog
2
2
  class Model
3
3
 
4
- def self._load(marshalled)
5
- new(Marshal.load(marshalled))
6
- end
7
-
8
- def self.aliases
9
- @aliases ||= {}
10
- end
11
-
12
- def self.attributes
13
- @attributes ||= []
14
- end
15
-
16
- def self.attribute(name, other_names = [])
17
- class_eval <<-EOS, __FILE__, __LINE__
18
- attr_accessor :#{name}
19
- EOS
20
- @attributes ||= []
21
- @attributes |= [name]
22
- for other_name in [*other_names]
23
- aliases[other_name] = name
24
- end
25
- end
26
-
27
- def self.identity(name, other_names = [])
28
- @identity = name
29
- self.attribute(name, other_names)
30
- end
31
-
32
- def _dump
33
- Marshal.dump(attributes)
34
- end
4
+ extend Attributes::ClassMethods
5
+ include Attributes::InstanceMethods
35
6
 
36
7
  attr_accessor :connection
37
8
 
38
- def attributes
39
- attributes = {}
40
- for attribute in self.class.attributes
41
- attributes[attribute] = send("#{attribute}")
42
- end
43
- attributes
44
- end
45
-
46
9
  def collection
47
10
  @collection
48
11
  end
49
12
 
50
- def identity
51
- send(self.class.instance_variable_get('@identity'))
52
- end
53
-
54
- def identity=(new_identity)
55
- send("#{identity}=", new_identity)
56
- end
57
-
58
13
  def initialize(new_attributes = {})
59
14
  merge_attributes(new_attributes)
60
15
  end
@@ -72,21 +27,6 @@ module Fog
72
27
  data
73
28
  end
74
29
 
75
- def merge_attributes(new_attributes = {})
76
- for key, value in new_attributes
77
- if aliased_key = self.class.aliases[key]
78
- send("#{aliased_key}=", value)
79
- else
80
- send("#{key}=", value)
81
- end
82
- end
83
- self
84
- end
85
-
86
- def new_record?
87
- !identity
88
- end
89
-
90
30
  def reload
91
31
  if data = collection.get(identity)
92
32
  new_attributes = data.attributes
@@ -95,20 +35,6 @@ module Fog
95
35
  end
96
36
  end
97
37
 
98
- def requires(*args)
99
- missing = []
100
- for arg in [:connection] | args
101
- missing << arg unless send("#{arg}")
102
- end
103
- unless missing.empty?
104
- if missing.length == 1
105
- raise(ArgumentError, "#{missing.first} is required for this operation")
106
- else
107
- raise(ArgumentError, "#{missing[0...-1].join(", ")} and #{missing[-1]} are required for this operation")
108
- end
109
- end
110
- end
111
-
112
38
  def to_json
113
39
  attributes.to_json
114
40
  end
@@ -127,13 +53,5 @@ module Fog
127
53
  @collection = new_collection
128
54
  end
129
55
 
130
- def remap_attributes(attributes, mapping)
131
- for key, value in mapping
132
- if attributes.key?(key)
133
- attributes[value] = attributes.delete(key)
134
- end
135
- end
136
- end
137
-
138
56
  end
139
57
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 6
9
- version: 0.1.6
8
+ - 7
9
+ version: 0.1.7
10
10
  platform: ruby
11
11
  authors:
12
12
  - geemus (Wesley Beary)
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-06-06 00:00:00 -07:00
17
+ date: 2010-06-07 00:00:00 -07:00
18
18
  default_executable: fog
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -149,6 +149,7 @@ files:
149
149
  - examples/bluebox_create.rb
150
150
  - fog.gemspec
151
151
  - lib/fog.rb
152
+ - lib/fog/attributes.rb
152
153
  - lib/fog/aws.rb
153
154
  - lib/fog/aws/bin.rb
154
155
  - lib/fog/aws/ec2.rb