fog 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/Gemfile.lock +3 -3
- data/fog.gemspec +1 -1
- data/lib/fog.rb +1 -1
- data/lib/fog/attributes.rb +72 -70
- data/lib/fog/bluebox/models/server.rb +1 -1
- data/lib/fog/bluebox/requests/create_block.rb +1 -1
- data/lib/fog/collection.rb +19 -14
- data/lib/fog/model.rb +2 -2
- metadata +2 -2
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -31,7 +31,7 @@ dependencies:
|
|
31
31
|
excon:
|
32
32
|
group:
|
33
33
|
- :default
|
34
|
-
version: ">= 0.0.
|
34
|
+
version: ">= 0.0.26"
|
35
35
|
builder:
|
36
36
|
group:
|
37
37
|
- :default
|
@@ -50,7 +50,7 @@ specs:
|
|
50
50
|
- builder:
|
51
51
|
version: 2.1.2
|
52
52
|
- excon:
|
53
|
-
version: 0.0.
|
53
|
+
version: 0.0.26
|
54
54
|
- formatador:
|
55
55
|
version: 0.0.14
|
56
56
|
- gestalt:
|
@@ -69,7 +69,7 @@ specs:
|
|
69
69
|
version: 0.4.0
|
70
70
|
- shindo:
|
71
71
|
version: 0.1.4
|
72
|
-
hash:
|
72
|
+
hash: da3f548f91388bc9e002c42ee2a4488bc8db9991
|
73
73
|
sources:
|
74
74
|
- Rubygems:
|
75
75
|
uri: http://gemcutter.org
|
data/fog.gemspec
CHANGED
@@ -7,7 +7,7 @@ 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.
|
10
|
+
s.version = '0.1.8'
|
11
11
|
s.date = '2010-06-07'
|
12
12
|
s.rubyforge_project = 'fog'
|
13
13
|
|
data/lib/fog.rb
CHANGED
data/lib/fog/attributes.rb
CHANGED
@@ -1,96 +1,98 @@
|
|
1
|
-
module
|
2
|
-
module
|
1
|
+
module Fog
|
2
|
+
module Attributes
|
3
|
+
module ClassMethods
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
5
|
+
def _load(marshalled)
|
6
|
+
new(Marshal.load(marshalled))
|
7
|
+
end
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
def aliases
|
10
|
+
@aliases ||= {}
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
def attributes
|
14
|
+
@attributes ||= []
|
15
|
+
end
|
16
|
+
|
17
|
+
def attribute(name, other_names = [])
|
18
|
+
class_eval <<-EOS, __FILE__, __LINE__
|
19
|
+
attr_accessor :#{name}
|
20
|
+
EOS
|
21
|
+
@attributes ||= []
|
22
|
+
@attributes |= [name]
|
23
|
+
for other_name in [*other_names]
|
24
|
+
aliases[other_name] = name
|
25
|
+
end
|
26
|
+
end
|
15
27
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
EOS
|
20
|
-
@attributes ||= []
|
21
|
-
@attributes |= [name]
|
22
|
-
for other_name in [*other_names]
|
23
|
-
aliases[other_name] = name
|
28
|
+
def identity(name, other_names = [])
|
29
|
+
@identity = name
|
30
|
+
self.attribute(name, other_names)
|
24
31
|
end
|
25
|
-
end
|
26
32
|
|
27
|
-
def identity(name, other_names = [])
|
28
|
-
@identity = name
|
29
|
-
self.attribute(name, other_names)
|
30
33
|
end
|
31
34
|
|
32
|
-
|
35
|
+
module InstanceMethods
|
33
36
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
Marshal.dump(attributes)
|
38
|
-
end
|
37
|
+
def _dump
|
38
|
+
Marshal.dump(attributes)
|
39
|
+
end
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
def attributes
|
42
|
+
attributes = {}
|
43
|
+
for attribute in self.class.attributes
|
44
|
+
attributes[attribute] = send("#{attribute}")
|
45
|
+
end
|
46
|
+
attributes
|
44
47
|
end
|
45
|
-
attributes
|
46
|
-
end
|
47
48
|
|
48
|
-
|
49
|
-
|
50
|
-
|
49
|
+
def identity
|
50
|
+
send(self.class.instance_variable_get('@identity'))
|
51
|
+
end
|
51
52
|
|
52
|
-
|
53
|
-
|
54
|
-
|
53
|
+
def identity=(new_identity)
|
54
|
+
send("#{self.class.instance_variable_get('@identity')}=", new_identity)
|
55
|
+
end
|
55
56
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
57
|
+
def merge_attributes(new_attributes = {})
|
58
|
+
for key, value in new_attributes
|
59
|
+
if aliased_key = self.class.aliases[key]
|
60
|
+
send("#{aliased_key}=", value)
|
61
|
+
else
|
62
|
+
send("#{key}=", value)
|
63
|
+
end
|
62
64
|
end
|
65
|
+
self
|
63
66
|
end
|
64
|
-
self
|
65
|
-
end
|
66
67
|
|
67
|
-
|
68
|
-
|
69
|
-
end
|
70
|
-
|
71
|
-
def requires(*args)
|
72
|
-
missing = []
|
73
|
-
for arg in [:connection] | args
|
74
|
-
missing << arg unless send("#{arg}")
|
68
|
+
def new_record?
|
69
|
+
!identity
|
75
70
|
end
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
71
|
+
|
72
|
+
def requires(*args)
|
73
|
+
missing = []
|
74
|
+
for arg in [:connection] | args
|
75
|
+
missing << arg unless send("#{arg}")
|
76
|
+
end
|
77
|
+
unless missing.empty?
|
78
|
+
if missing.length == 1
|
79
|
+
raise(ArgumentError, "#{missing.first} is required for this operation")
|
80
|
+
else
|
81
|
+
raise(ArgumentError, "#{missing[0...-1].join(", ")} and #{missing[-1]} are required for this operation")
|
82
|
+
end
|
81
83
|
end
|
82
84
|
end
|
83
|
-
end
|
84
85
|
|
85
|
-
|
86
|
+
private
|
86
87
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
88
|
+
def remap_attributes(attributes, mapping)
|
89
|
+
for key, value in mapping
|
90
|
+
if attributes.key?(key)
|
91
|
+
attributes[value] = attributes.delete(key)
|
92
|
+
end
|
91
93
|
end
|
92
94
|
end
|
93
|
-
end
|
94
95
|
|
96
|
+
end
|
95
97
|
end
|
96
|
-
end
|
98
|
+
end
|
@@ -22,7 +22,7 @@ module Fog
|
|
22
22
|
:expects => 200,
|
23
23
|
:method => 'POST',
|
24
24
|
:path => '/api/blocks.json',
|
25
|
-
:query => {'product' => product_id, 'template' =>
|
25
|
+
:query => {'product' => product_id, 'template' => template_id}.merge!(options)
|
26
26
|
)
|
27
27
|
end
|
28
28
|
|
data/lib/fog/collection.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
module Fog
|
2
2
|
class Collection < Array
|
3
3
|
|
4
|
-
extend Attributes::ClassMethods
|
5
|
-
include Attributes::InstanceMethods
|
4
|
+
extend Fog::Attributes::ClassMethods
|
5
|
+
include Fog::Attributes::InstanceMethods
|
6
6
|
|
7
7
|
Array.public_instance_methods(false).each do |method|
|
8
8
|
class_eval <<-RUBY
|
9
9
|
def #{method}(*args)
|
10
|
-
|
10
|
+
unless @loaded
|
11
|
+
lazy_load
|
12
|
+
end
|
11
13
|
super
|
12
14
|
end
|
13
15
|
RUBY
|
@@ -16,9 +18,11 @@ module Fog
|
|
16
18
|
%w[reject select].each do |method|
|
17
19
|
class_eval <<-RUBY
|
18
20
|
def #{method}(*args)
|
19
|
-
|
21
|
+
unless @loaded
|
22
|
+
lazy_load
|
23
|
+
end
|
20
24
|
data = super
|
21
|
-
|
25
|
+
result = self.clone.clear.concat(data)
|
22
26
|
end
|
23
27
|
RUBY
|
24
28
|
end
|
@@ -33,6 +37,11 @@ module Fog
|
|
33
37
|
|
34
38
|
attr_accessor :connection
|
35
39
|
|
40
|
+
def clear
|
41
|
+
@loaded = true
|
42
|
+
super
|
43
|
+
end
|
44
|
+
|
36
45
|
def create(attributes = {})
|
37
46
|
object = new(attributes)
|
38
47
|
object.save
|
@@ -41,7 +50,6 @@ module Fog
|
|
41
50
|
|
42
51
|
def initialize(attributes = {})
|
43
52
|
merge_attributes(attributes)
|
44
|
-
@loaded = false
|
45
53
|
end
|
46
54
|
|
47
55
|
def inspect
|
@@ -69,10 +77,7 @@ module Fog
|
|
69
77
|
end
|
70
78
|
|
71
79
|
def load(objects)
|
72
|
-
|
73
|
-
clear
|
74
|
-
end
|
75
|
-
@loaded = true
|
80
|
+
clear
|
76
81
|
for object in objects
|
77
82
|
self << new(object)
|
78
83
|
end
|
@@ -93,7 +98,9 @@ module Fog
|
|
93
98
|
end
|
94
99
|
|
95
100
|
def reload
|
96
|
-
|
101
|
+
clear
|
102
|
+
lazy_load
|
103
|
+
self
|
97
104
|
end
|
98
105
|
|
99
106
|
def table(attributes = nil)
|
@@ -107,9 +114,7 @@ module Fog
|
|
107
114
|
private
|
108
115
|
|
109
116
|
def lazy_load
|
110
|
-
|
111
|
-
self.all
|
112
|
-
end
|
117
|
+
self.all
|
113
118
|
end
|
114
119
|
|
115
120
|
end
|
data/lib/fog/model.rb
CHANGED