bodhi-slam 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a1190f2e6cece5ef43cb0e44f2ae900b1d84768a
4
- data.tar.gz: a1f3103fe42f11f76a4b6385cc608cd195fe1f4d
3
+ metadata.gz: 74f006a6012ceaab5f918a7b6832a832d1dbf9b4
4
+ data.tar.gz: fe5a4a8bdc2c6e803ef560f892fa60a56ab3b79b
5
5
  SHA512:
6
- metadata.gz: ea4a4951ac8e977e7ed264b72517306f83f28e25ec381ec32601f7af193158dcf2201d5376bd067b7c980822fed001d8c431672fbd3b82a4baefb16fcf31ecca
7
- data.tar.gz: d24addea94ee3896b43737fb5f1422979b281367802e1145b875650dd0a51eb951e73d830111e1327ce087bace2240fc43664860ac34b5f6341cc134c02157db
6
+ metadata.gz: 8ca2122a8f1ae97c087033e60d81befc12b3c90f2e7e34595e75cd1907e805192dde8c5eaf870738aa29db56b9c18939cd82eeae7c73193d879e194dab525b7a
7
+ data.tar.gz: 9db6d4a31a8893620aded4fb57dcc44b5589c5ae3e283b8d3bc34dd9a1b91bcaf84226998e05aa3d6db47afe7e230953a27020098ec74896b9238e8aa98f23f3
@@ -4,22 +4,21 @@ require "json"
4
4
  require "time"
5
5
 
6
6
  require 'bodhi-slam/context'
7
+ require 'bodhi-slam/errors'
7
8
  require 'bodhi-slam/resource'
8
9
 
9
10
  class BodhiSlam
10
11
  def self.context(params, &block)
11
12
  bodhi_context = BodhiContext.new params
12
- bodhi_context.validate!
13
-
14
- puts "Switching context to: #{bodhi_context.attributes}"
15
-
13
+ raise bodhi_context.errors unless bodhi_context.valid?
14
+
15
+ #puts "Switching context to: #{bodhi_context.attributes}"
16
16
  yield bodhi_context
17
-
18
- puts "Exiting context: #{bodhi_context.attributes}"
17
+ #puts "Exiting context: #{bodhi_context.attributes}"
19
18
  end
20
19
 
21
20
  def self.analyze(context)
22
- context.validate!
21
+ raise context.errors unless context.valid?
23
22
 
24
23
  #Get the types for this namespace
25
24
  result = context.connection.get do |request|
@@ -1,5 +1,5 @@
1
1
  class BodhiContext
2
- attr_reader :connection, :server, :namespace,
2
+ attr_reader :errors, :connection, :server, :namespace,
3
3
  :credentials, :credentials_type, :credentials_header
4
4
 
5
5
  def initialize(params)
@@ -22,19 +22,38 @@ class BodhiContext
22
22
  @credentials_header = "Authorization"
23
23
  @credentials_type = "HTTP_BASIC"
24
24
  end
25
+
26
+ @errors = Bodhi::Errors.new
25
27
  end
26
28
 
27
29
  def attributes
28
30
  attributes = Hash.new
29
31
  self.instance_variables.each do |variable|
30
32
  attribute_name = variable.to_s.delete('@').to_sym
31
- attributes[attribute_name] = send(attribute_name) unless [:connection, :credentials_header].include?(attribute_name)
33
+ attributes[attribute_name] = send(attribute_name)
32
34
  end
33
35
  attributes
34
36
  end
35
37
 
36
- def validate!
37
- raise ArgumentError, "Server URL must be a String" unless server.is_a?(String)
38
- raise ArgumentError, "Namespace name must be a String" unless namespace.is_a?(String)
38
+ # - Runs all the specified validations and returns true if no errors were added otherwise false.
39
+ def valid?
40
+ errors.add(:server, "must be present") if server.nil?
41
+ errors.add(:server, "must be a string") unless server.is_a? String
42
+
43
+ errors.add(:namespace, "must be present") if namespace.nil?
44
+ errors.add(:namespace, "must be a string") unless namespace.is_a? String
45
+
46
+ return !errors.messages.any?
47
+ end
48
+
49
+ # - Performs the opposite of valid?. Returns true if errors were added, false otherwise.
50
+ def invalid?
51
+ errors.add(:server, "must be present") if server.nil?
52
+ errors.add(:server, "must be a string") unless server.is_a? String
53
+
54
+ errors.add(:namespace, "must be present") if namespace.nil?
55
+ errors.add(:namespace, "must be a string") unless namespace.is_a? String
56
+
57
+ return errors.messages.any?
39
58
  end
40
59
  end
@@ -0,0 +1,24 @@
1
+ module Bodhi
2
+ class Errors < Exception
3
+ attr_accessor :messages
4
+
5
+ def initialize(errors={})
6
+ @messages = errors
7
+ end
8
+
9
+ def add(symbol, msg)
10
+ @messages[symbol] = [] unless @messages.has_key?(symbol)
11
+ @messages[symbol].push(msg)
12
+ end
13
+
14
+ def clear
15
+ @messages.clear
16
+ end
17
+
18
+ def full_messages
19
+ results = []
20
+ @messages.each{ |key, values| values.each{ |value| results.push("#{key} #{value}") }}
21
+ results
22
+ end
23
+ end
24
+ end
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.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Will Davis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-11 00:00:00.000000000 Z
11
+ date: 2015-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: factory_girl
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  description: Generate data and push to the Bodhi API
56
70
  email: will.davis@hotschedules.com
57
71
  executables: []
@@ -60,6 +74,7 @@ extra_rdoc_files: []
60
74
  files:
61
75
  - lib/bodhi-slam.rb
62
76
  - lib/bodhi-slam/context.rb
77
+ - lib/bodhi-slam/errors.rb
63
78
  - lib/bodhi-slam/resource.rb
64
79
  homepage:
65
80
  licenses: