fog-core 1.27.2 → 1.27.3
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 +4 -4
- data/changelog.md +7 -0
- data/lib/fog/core.rb +3 -0
- data/lib/fog/core/attributes.rb +2 -1
- data/lib/fog/core/collection.rb +15 -37
- data/lib/fog/core/logger.rb +2 -2
- data/lib/fog/core/version.rb +1 -1
- data/lib/fog/formatador.rb +66 -0
- data/spec/fog_attribute_spec.rb +39 -0
- data/spec/formatador_spec.rb +57 -0
- data/spec/spec_helper.rb +0 -2
- data/spec/storage_spec.rb +5 -5
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05926065513096bbd243c048472185d94fff85dc
|
4
|
+
data.tar.gz: 07586ba0a3850cb661496316589f8e691bd38972
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3c1803c12f6e915226ec157457d769ede0c28debdd5ce9651a253f662d6b651df268ff8748a3070e6836fa3cd84badfb805fd4b9aea0fc3a3ad0065f51544d2
|
7
|
+
data.tar.gz: 29295752f87c18ae39bed3385f9976ff3140106d6446d339c370c3015bad8f4b13dec7cdb0d1a7b76cde270459d68be2e3a09d60e7d744dbcb0b0a2b9327799d
|
data/changelog.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
1.27.3 12/01/2012
|
2
|
+
==========================================================
|
3
|
+
|
4
|
+
rubocop fixes for fog collection
|
5
|
+
simpler ruby version checking/skipping
|
6
|
+
fix requires_one
|
7
|
+
|
1
8
|
1.27.2 18/12/2014
|
2
9
|
==========================================================
|
3
10
|
|
data/lib/fog/core.rb
CHANGED
data/lib/fog/core/attributes.rb
CHANGED
@@ -155,7 +155,8 @@ module Fog
|
|
155
155
|
end
|
156
156
|
|
157
157
|
def requires_one(*args)
|
158
|
-
|
158
|
+
missing = missing_attributes(args)
|
159
|
+
return unless missing.length == args.length
|
159
160
|
raise(ArgumentError, "#{missing[0...-1].join(", ")} or #{missing[-1]} are required for this operation")
|
160
161
|
end
|
161
162
|
|
data/lib/fog/core/collection.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
require "fog/core/deprecated_connection_accessors"
|
2
2
|
|
3
3
|
module Fog
|
4
|
+
# Fog::Collection
|
4
5
|
class Collection < Array
|
5
6
|
extend Fog::Attributes::ClassMethods
|
6
7
|
include Fog::Attributes::InstanceMethods
|
7
8
|
include Fog::Core::DeprecatedConnectionAccessors
|
9
|
+
|
8
10
|
|
9
11
|
attr_reader :service
|
10
12
|
|
@@ -41,8 +43,7 @@ module Fog
|
|
41
43
|
end
|
42
44
|
|
43
45
|
def clear
|
44
|
-
@loaded = true
|
45
|
-
super
|
46
|
+
@loaded = true && super
|
46
47
|
end
|
47
48
|
|
48
49
|
def create(attributes = {})
|
@@ -52,8 +53,7 @@ module Fog
|
|
52
53
|
end
|
53
54
|
|
54
55
|
def destroy(identity)
|
55
|
-
|
56
|
-
object.destroy
|
56
|
+
new(:identity => identity).destroy
|
57
57
|
end
|
58
58
|
|
59
59
|
# Creates a new Fog::Collection based around the passed service
|
@@ -70,34 +70,11 @@ module Fog
|
|
70
70
|
end
|
71
71
|
|
72
72
|
def inspect
|
73
|
-
|
74
|
-
data = "#{Thread.current[:formatador].indentation}<#{self.class.name}\n"
|
75
|
-
Thread.current[:formatador].indent do
|
76
|
-
unless self.class.attributes.empty?
|
77
|
-
data << "#{Thread.current[:formatador].indentation}"
|
78
|
-
data << self.class.attributes.map { |attribute| "#{attribute}=#{send(attribute).inspect}" }.join(",\n#{Thread.current[:formatador].indentation}")
|
79
|
-
data << "\n"
|
80
|
-
end
|
81
|
-
data << "#{Thread.current[:formatador].indentation}["
|
82
|
-
unless self.empty?
|
83
|
-
data << "\n"
|
84
|
-
Thread.current[:formatador].indent do
|
85
|
-
data << map(&:inspect).join(", \n")
|
86
|
-
data << "\n"
|
87
|
-
end
|
88
|
-
data << Thread.current[:formatador].indentation
|
89
|
-
end
|
90
|
-
data << "]\n"
|
91
|
-
end
|
92
|
-
data << "#{Thread.current[:formatador].indentation}>"
|
93
|
-
data
|
73
|
+
Fog::Formatador.new(self)
|
94
74
|
end
|
95
75
|
|
96
76
|
def load(objects)
|
97
|
-
clear
|
98
|
-
objects.each do |object|
|
99
|
-
self << new(object)
|
100
|
-
end
|
77
|
+
clear && objects.each { |object| self << new(object) }
|
101
78
|
self
|
102
79
|
end
|
103
80
|
|
@@ -118,8 +95,7 @@ module Fog
|
|
118
95
|
end
|
119
96
|
|
120
97
|
def reload
|
121
|
-
clear
|
122
|
-
lazy_load
|
98
|
+
clear && lazy_load
|
123
99
|
self
|
124
100
|
end
|
125
101
|
|
@@ -137,18 +113,20 @@ module Fog
|
|
137
113
|
all
|
138
114
|
end
|
139
115
|
end
|
140
|
-
|
141
|
-
#
|
142
|
-
#
|
116
|
+
# Base class for collection classes whose 'all' method returns only a single
|
117
|
+
# page of results and passes the 'Marker' option along as
|
118
|
+
# self.filters[:marker]
|
143
119
|
class PagedCollection < Collection
|
144
120
|
def each(collection_filters = filters)
|
145
121
|
if block_given?
|
146
|
-
|
122
|
+
Kernel.loop do
|
123
|
+
break unless filters[:marker]
|
147
124
|
page = all(collection_filters)
|
148
|
-
# We need to explicitly use the base 'each' method here on the page,
|
125
|
+
# We need to explicitly use the base 'each' method here on the page,
|
126
|
+
# otherwise we get infinite recursion
|
149
127
|
base_each = Fog::Collection.instance_method(:each)
|
150
128
|
base_each.bind(page).call { |item| yield item }
|
151
|
-
end
|
129
|
+
end
|
152
130
|
end
|
153
131
|
self
|
154
132
|
end
|
data/lib/fog/core/logger.rb
CHANGED
@@ -31,9 +31,9 @@ module Fog
|
|
31
31
|
channel = @channels[key]
|
32
32
|
if channel
|
33
33
|
message = if channel.tty?
|
34
|
-
value.gsub(Formatador::PARSE_REGEX) { "\e[#{Formatador::STYLES[$1.to_sym]}m" }.gsub(Formatador::INDENT_REGEX, "")
|
34
|
+
value.gsub(::Formatador::PARSE_REGEX) { "\e[#{::Formatador::STYLES[$1.to_sym]}m" }.gsub(::Formatador::INDENT_REGEX, "")
|
35
35
|
else
|
36
|
-
value.gsub(Formatador::PARSE_REGEX, "").gsub(Formatador::INDENT_REGEX, "")
|
36
|
+
value.gsub(::Formatador::PARSE_REGEX, "").gsub(::Formatador::INDENT_REGEX, "")
|
37
37
|
end
|
38
38
|
channel.write(message)
|
39
39
|
end
|
data/lib/fog/core/version.rb
CHANGED
@@ -0,0 +1,66 @@
|
|
1
|
+
module Fog
|
2
|
+
# Fog::Formatador
|
3
|
+
class Formatador
|
4
|
+
attr_accessor :object, :string, :formatador
|
5
|
+
|
6
|
+
def initialize(obj)
|
7
|
+
@object = obj
|
8
|
+
@formatador ||= ::Formatador.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_s
|
12
|
+
return string unless string.nil?
|
13
|
+
init_string
|
14
|
+
indent { string << object_string }
|
15
|
+
(string << "#{indentation}>").dup
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def indent(&block)
|
21
|
+
formatador.indent(&block)
|
22
|
+
end
|
23
|
+
|
24
|
+
def indentation
|
25
|
+
formatador.indentation
|
26
|
+
end
|
27
|
+
|
28
|
+
def init_string
|
29
|
+
@string = "#{indentation}<#{object.class.name}\n"
|
30
|
+
end
|
31
|
+
|
32
|
+
def object_string
|
33
|
+
"#{attribute_string}#{nested_objects_string}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def attribute_string
|
37
|
+
if object.attributes.empty?
|
38
|
+
"#{indentation}#{object_attributes}\n"
|
39
|
+
else
|
40
|
+
""
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def nested_objects_string
|
45
|
+
if object.empty?
|
46
|
+
nested = "#{indentation}[\n"
|
47
|
+
indent { nested << indentation + inspect_object }
|
48
|
+
nested << "#{indentation}\n#{indentation}]\n"
|
49
|
+
nested
|
50
|
+
else
|
51
|
+
""
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def object_attributes
|
56
|
+
attrs = object.class.attributes.map do |attr|
|
57
|
+
"#{attr}=#{object.send(attr).inspect}"
|
58
|
+
end
|
59
|
+
attrs.join(",\n#{indentation}")
|
60
|
+
end
|
61
|
+
|
62
|
+
def inspect_object
|
63
|
+
object.map { |o| indentation + o.inspect }.join(", \n#{indentation}")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/spec/fog_attribute_spec.rb
CHANGED
@@ -59,6 +59,14 @@ class FogAttributeTestModel < Fog::Model
|
|
59
59
|
def service
|
60
60
|
Service.new
|
61
61
|
end
|
62
|
+
|
63
|
+
def requires_one_test
|
64
|
+
requires_one :key, :time
|
65
|
+
end
|
66
|
+
|
67
|
+
def requires_test
|
68
|
+
requires :string, :integer
|
69
|
+
end
|
62
70
|
end
|
63
71
|
|
64
72
|
describe "Fog::Attributes" do
|
@@ -334,6 +342,37 @@ describe "Fog::Attributes" do
|
|
334
342
|
end
|
335
343
|
end
|
336
344
|
|
345
|
+
describe "#requires_one" do
|
346
|
+
it "should require at least one attribute is supplied" do
|
347
|
+
FogAttributeTestModel.new(:key => :key, :time => Time.now).requires_one_test
|
348
|
+
FogAttributeTestModel.new(:time => Time.now).requires_one_test
|
349
|
+
FogAttributeTestModel.new(:key => :key).requires_one_test
|
350
|
+
FogAttributeTestModel.new(:key => :key, :integer => 1).requires_one_test
|
351
|
+
|
352
|
+
assert_raises ArgumentError do
|
353
|
+
FogAttributeTestModel.new(:integer => 1).requires_one_test
|
354
|
+
end
|
355
|
+
end
|
356
|
+
end
|
357
|
+
|
358
|
+
describe "#requires" do
|
359
|
+
it "should require all attributes are supplied" do
|
360
|
+
FogAttributeTestModel.new(:string => "string", :integer => 1).requires_test
|
361
|
+
|
362
|
+
assert_raises ArgumentError do
|
363
|
+
FogAttributeTestModel.new(:integer => 1).requires_test
|
364
|
+
end
|
365
|
+
|
366
|
+
assert_raises ArgumentError do
|
367
|
+
FogAttributeTestModel.new(:string => "string").requires_test
|
368
|
+
end
|
369
|
+
|
370
|
+
assert_raises ArgumentError do
|
371
|
+
FogAttributeTestModel.new(:key => :key).requires_test
|
372
|
+
end
|
373
|
+
end
|
374
|
+
end
|
375
|
+
|
337
376
|
describe ".has_many_identities" do
|
338
377
|
it "should return an instance of Fog::Association" do
|
339
378
|
model.many_identities = ["456"]
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
class TestCase < Fog::Collection
|
4
|
+
def all
|
5
|
+
end
|
6
|
+
def map(*_args)
|
7
|
+
%w(foo bar)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.attributes
|
11
|
+
%w(this that)
|
12
|
+
end
|
13
|
+
|
14
|
+
def this
|
15
|
+
%w(this that)
|
16
|
+
end
|
17
|
+
|
18
|
+
def that
|
19
|
+
%w(that this)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
test_case_str = <<-EOL
|
24
|
+
<TestCase
|
25
|
+
this=["this", "that"],
|
26
|
+
that=["that", "this"]
|
27
|
+
[
|
28
|
+
foo,
|
29
|
+
bar
|
30
|
+
]
|
31
|
+
>
|
32
|
+
EOL
|
33
|
+
|
34
|
+
test_case_str.chomp!
|
35
|
+
|
36
|
+
describe Fog::Formatador do
|
37
|
+
|
38
|
+
def setup
|
39
|
+
@formatador = Fog::Formatador.new(TestCase.new)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "raises for missing required arguments" do
|
43
|
+
assert_raises(ArgumentError) { Fog::Formatador.new }
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should instansiate" do
|
47
|
+
@formatador.must_be_instance_of Fog::Formatador
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should respond to_s" do
|
51
|
+
@formatador.must_respond_to :to_s
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should give a string representation of object with proper indentation" do
|
55
|
+
"#{@formatador}".must_equal test_case_str
|
56
|
+
end
|
57
|
+
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/storage_spec.rb
CHANGED
@@ -94,15 +94,15 @@ describe "Fog::Storage" do
|
|
94
94
|
end
|
95
95
|
|
96
96
|
describe ".get_body_size" do
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
if current_version >= Gem::Version.new("1.9.0")
|
101
|
-
it "doesn't alter the encoding of the string passed to it" do
|
97
|
+
it "doesn't alter the encoding of the string passed to it" do
|
98
|
+
# Ruby 1.8 doesn't support string encodings, so we can't test that
|
99
|
+
if RUBY_VERSION >= "1.9.3"
|
102
100
|
body = "foo".encode("UTF-8")
|
103
101
|
Fog::Storage.get_body_size(body)
|
104
102
|
|
105
103
|
assert_equal("UTF-8", body.encoding.to_s)
|
104
|
+
else
|
105
|
+
skip
|
106
106
|
end
|
107
107
|
end
|
108
108
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fog-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.27.
|
4
|
+
version: 1.27.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evan Light
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2015-01-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: builder
|
@@ -272,6 +272,7 @@ files:
|
|
272
272
|
- lib/fog/core/wait_for_defaults.rb
|
273
273
|
- lib/fog/core/whitelist_keys.rb
|
274
274
|
- lib/fog/dns.rb
|
275
|
+
- lib/fog/formatador.rb
|
275
276
|
- lib/fog/identity.rb
|
276
277
|
- lib/fog/image.rb
|
277
278
|
- lib/fog/metering.rb
|
@@ -304,6 +305,7 @@ files:
|
|
304
305
|
- spec/fake_app/models/model.rb
|
305
306
|
- spec/fake_app/requests/request.rb
|
306
307
|
- spec/fog_attribute_spec.rb
|
308
|
+
- spec/formatador_spec.rb
|
307
309
|
- spec/identity_spec.rb
|
308
310
|
- spec/mocking_spec.rb
|
309
311
|
- spec/service_spec.rb
|
@@ -351,6 +353,7 @@ test_files:
|
|
351
353
|
- spec/fake_app/models/model.rb
|
352
354
|
- spec/fake_app/requests/request.rb
|
353
355
|
- spec/fog_attribute_spec.rb
|
356
|
+
- spec/formatador_spec.rb
|
354
357
|
- spec/identity_spec.rb
|
355
358
|
- spec/mocking_spec.rb
|
356
359
|
- spec/service_spec.rb
|