bodhi-slam 0.5.3 → 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bodhi-slam/batches/resource.rb +1 -1
- data/lib/bodhi-slam/factory.rb +1 -28
- data/lib/bodhi-slam/properties.rb +9 -1
- data/lib/bodhi-slam/resource.rb +4 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5555fc31ea61537f2cf853ef20bc9abcc3be90cd
|
4
|
+
data.tar.gz: 9e8a0aef642e02f2a562f882efb5e7209783ea5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95543f83c7aa4df83dd787c8286104408ef8c9f2eba82ed6716e7140549e2ed31ba7fd54710e1b3aded240d904b805bab3c4cb20ff50e83ea47ab28fc362b7c3
|
7
|
+
data.tar.gz: 07de99d9bbdc16829deb95a056cc979ac959d03ed054ecdb60b5e997ca7c411e0402d3c25ba9c8a50d68c50f4f0eaad7cfe075a640cd231f943e7c75a667b6ad
|
@@ -25,7 +25,7 @@ module Bodhi
|
|
25
25
|
request.url "/#{context.namespace}/resources/#{type}"
|
26
26
|
request.headers['Content-Type'] = 'application/json'
|
27
27
|
request.headers[context.credentials_header] = context.credentials
|
28
|
-
request.body = records.to_json
|
28
|
+
request.body = records.map(&:attributes).to_json
|
29
29
|
end
|
30
30
|
|
31
31
|
if response.status != 200
|
data/lib/bodhi-slam/factory.rb
CHANGED
@@ -33,8 +33,7 @@ module Bodhi
|
|
33
33
|
memo.merge({ k.to_sym => v})
|
34
34
|
end
|
35
35
|
|
36
|
-
object = klass.new
|
37
|
-
object.bodhi_context = options[:bodhi_context]
|
36
|
+
object = klass.new(bodhi_context: options[:bodhi_context])
|
38
37
|
@generators.each_pair do |attribute, generator|
|
39
38
|
if options.has_key?(attribute)
|
40
39
|
object.send("#{attribute}=", options[attribute])
|
@@ -60,19 +59,6 @@ module Bodhi
|
|
60
59
|
# Resource.factory.create(context) # => #<Resource:0x007fbff403e808 @name="2-3lmwp^oef@245">
|
61
60
|
# Resource.factory.create(context, name: "test") # => #<Resource:0x007fbff403e808 @name="test">
|
62
61
|
def create(options={})
|
63
|
-
# symbolize the option keys
|
64
|
-
options = options.reduce({}) do |memo, (k, v)|
|
65
|
-
memo.merge({ k.to_sym => v})
|
66
|
-
end
|
67
|
-
|
68
|
-
if options[:bodhi_context].nil?
|
69
|
-
raise ArgumentError.new("Missing option :bodhi_context")
|
70
|
-
end
|
71
|
-
|
72
|
-
if options[:bodhi_context].invalid?
|
73
|
-
raise options[:bodhi_context].errors, options[:bodhi_context].errors.to_a.to_s
|
74
|
-
end
|
75
|
-
|
76
62
|
object = build(options)
|
77
63
|
object.save!
|
78
64
|
object
|
@@ -84,19 +70,6 @@ module Bodhi
|
|
84
70
|
# Resource.factory.create_list(10, context) # => [#<Resource:0x007fbff403e808 @name="2-3lmwp^oef@245">, #<Resource:0x007fbff403e808 @name="p7:n#$903<u1">, ...]
|
85
71
|
# Resource.factory.create_list(10, context, name: "test") # => [#<Resource:0x007fbff403e808 @name="test">, #<Resource:0x007fbff403e808 @name="test">, ...]
|
86
72
|
def create_list(size, options={})
|
87
|
-
# symbolize the option keys
|
88
|
-
options = options.reduce({}) do |memo, (k, v)|
|
89
|
-
memo.merge({ k.to_sym => v})
|
90
|
-
end
|
91
|
-
|
92
|
-
if options[:bodhi_context].nil?
|
93
|
-
raise ArgumentError.new("Missing option :bodhi_context")
|
94
|
-
end
|
95
|
-
|
96
|
-
if options[:bodhi_context].invalid?
|
97
|
-
raise options[:bodhi_context].errors, options[:bodhi_context].errors.to_a.to_s
|
98
|
-
end
|
99
|
-
|
100
73
|
resources = build_list(size, options)
|
101
74
|
resources.each{ |resource| resource.save! }
|
102
75
|
resources
|
@@ -42,8 +42,16 @@ module Bodhi
|
|
42
42
|
# object.attributes # => { foo: "test", bar: 12345 }
|
43
43
|
def attributes
|
44
44
|
attributes = Hash.new
|
45
|
+
|
45
46
|
self.class.properties.each do |property|
|
46
|
-
|
47
|
+
value = send(property)
|
48
|
+
if value.respond_to?(:attributes)
|
49
|
+
attributes[property] = value.attributes.delete_if { |k, v| v.nil? }
|
50
|
+
elsif value.is_a?(Array) && value.first.respond_to?(:attributes)
|
51
|
+
attributes[property] = value.map(&:attributes).collect{ |item| item.delete_if { |k, v| v.nil? } }
|
52
|
+
else
|
53
|
+
attributes[property] = value
|
54
|
+
end
|
47
55
|
end
|
48
56
|
|
49
57
|
attributes.delete_if { |k, v| v.nil? }
|
data/lib/bodhi-slam/resource.rb
CHANGED
@@ -276,6 +276,10 @@ module Bodhi
|
|
276
276
|
# obj.save!
|
277
277
|
# obj.persisted? # => true
|
278
278
|
def save!
|
279
|
+
if bodhi_context.invalid?
|
280
|
+
raise Bodhi::ContextErrors.new(bodhi_context.errors.messages), bodhi_context.errors.to_a.to_s
|
281
|
+
end
|
282
|
+
|
279
283
|
result = bodhi_context.connection.post do |request|
|
280
284
|
request.url "/#{bodhi_context.namespace}/resources/#{self.class}"
|
281
285
|
request.headers['Content-Type'] = 'application/json'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bodhi-slam
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- willdavis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|