lacerda 0.7.0 → 0.8.0

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: b79f31c341b389ee76539bade775431468b9bd50
4
- data.tar.gz: 4cfc0aaf1282b2b0cfe6982c0f33299fafefeb6e
3
+ metadata.gz: 732b9947f1b14ae426fb81521f97c71db31787a8
4
+ data.tar.gz: 568fccf33cecefd14d595e616d9fa5cd8cc165d5
5
5
  SHA512:
6
- metadata.gz: 7d5be7e36ab570f3a860a52a91d7006248ddbf48751e44f7b8cf2437e5db8dea4aeee63c5583d6b301e533c02b12cd6c4b7337f75b003b3822362d7e30370e43
7
- data.tar.gz: 90847e492f4b7bbede6bc1ca00a09a008fd89cdb3f07e6e6ed0e462e72a44d57ee0a5734ff5250e05dd4f867474bcaaa4a5eda1891c9796fb6c8735337945b85
6
+ metadata.gz: 4da97e585d8d88580e630c8eaeaba6ffb83f5cf47da8771c340e045049f5394a02360769171cb7ed6ff19217e255fb80136bf37fe15c9673cfefa9d5750b5e59
7
+ data.tar.gz: 2f91d653697e862dc113d8c0ab1ab9da8b1e7e81d4c2b5a0b298e99cf2d1c24043395647b55a489ae33797265320e24ceebf368c515f7da77bfd144e86323a5e
data/CHANGELOG.markdown CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.8.0 (30-Oct-15)
2
+ - support for custom reporters
3
+ - extract current output into and stdout reporter
4
+
1
5
  # 0.7.0 (30-Oct-15)
2
6
  - change ServiceName:ObjectName to ServiceName::ObjectName
3
7
 
@@ -1,4 +1,5 @@
1
1
  require 'active_support/core_ext/hash/indifferent_access'
2
+ require 'active_support/core_ext/object/try'
2
3
 
3
4
  module Lacerda
4
5
  class Infrastructure
@@ -15,24 +16,35 @@ module Lacerda
15
16
  @services = nil
16
17
  end
17
18
 
18
- def contracts_fulfilled?
19
+ def contracts_fulfilled?(reporter = nil)
20
+ reporter = Lacerda.validate_reporter(reporter)
21
+
19
22
  @mutex1.synchronize do
20
23
  @errors = {}
21
24
 
22
25
  # Check for incompatibility in published objects
26
+ reporter.try(:check_publishing)
23
27
  publishers.each do |publisher|
24
- publisher.satisfies_consumers?(verbose: @verbose)
28
+ reporter.try(:check_publisher, publisher)
29
+ publisher.satisfies_consumers?(verbose: @verbose, reporter: reporter)
25
30
  next if publisher.errors.empty?
26
31
  @errors.merge! publisher.errors
27
32
  end
28
33
 
29
34
  # Check for missing publishers
35
+ reporter.try(:check_consuming)
30
36
  missing_publishers = {}
31
37
  consumers.each do |consumer|
38
+ reporter.try(:check_consumer, consumer)
32
39
  consumer.consumed_objects.each do |object|
33
- next if object.publisher
34
- missing_publishers[object.publisher_name.camelize] ||= []
35
- missing_publishers[object.publisher_name.camelize] << consumer.name.camelize
40
+ if object.publisher
41
+ reporter.try(:object_publisher_existing, object, true)
42
+ next
43
+ else
44
+ reporter.try(:object_publisher_existing, object, false)
45
+ missing_publishers[object.publisher_name.camelize] ||= []
46
+ missing_publishers[object.publisher_name.camelize] << consumer.name.camelize
47
+ end
36
48
  end
37
49
  end
38
50
 
@@ -45,6 +57,8 @@ module Lacerda
45
57
  errors["Missing publishers: "] = missing
46
58
  end
47
59
 
60
+ reporter.try(:result, @errors)
61
+
48
62
  @errors.empty?
49
63
  end
50
64
  end
@@ -8,9 +8,12 @@ module Lacerda
8
8
  @comparator.errors
9
9
  end
10
10
 
11
- def satisfies?(consumer)
11
+ def satisfies?(consumer, reporter = nil)
12
+ Lacerda.validate_reporter(reporter)
12
13
  @comparator = Compare::JsonSchema.new(@schema)
13
- @comparator.contains?(consumer.consume.scoped_schema(service), consumer.name)
14
+ result = @comparator.contains?(consumer.consume.scoped_schema(service), consumer.name)
15
+ reporter.try(:consume_specification_satisfied, consumer, result)
16
+ result
14
17
  end
15
18
 
16
19
  def object(name)
@@ -0,0 +1,40 @@
1
+ # This is so you can write your own reporters
2
+ module Lacerda
3
+ class Reporter
4
+ def initialize(options = {})
5
+ end
6
+
7
+ def check_publishing
8
+ # Called before all publishers are iterated to check if they satisfy
9
+ # their consumers.
10
+ end
11
+
12
+ def check_publisher(publishing_service)
13
+ # Called before one single publisher is checked against its consumers
14
+ end
15
+
16
+ def object_publish_specification_valid(consumed_object, is_valid)
17
+ # Called after a consumed object's specification has been checked against
18
+ # the publisher's specification of that object.
19
+ end
20
+
21
+ def check_consuming
22
+ # Called before all consumers' consumed objects are iterated to make
23
+ # sure they have a publisher that meets their specification.
24
+ end
25
+
26
+ def check_consumer(consuming_service)
27
+ # Called before all consumed objects are iterated
28
+ end
29
+
30
+ def object_publisher_existing(consumed_object, is_published)
31
+ # Called after a consumed object was inspected (does a publish specification
32
+ # for this object exist?)
33
+ end
34
+
35
+ def result(errors)
36
+ # Called when everything is done with an array of errors. If that array
37
+ # is empty, go ahead and assume all specifications are valid
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,34 @@
1
+ require 'lacerda/reporter'
2
+
3
+ module Lacerda
4
+ module Reporters
5
+ class Multi < Lacerda::Reporter
6
+ def initialize(*reporters)
7
+ @reporters = []
8
+ [reporters].flatten.each do |r|
9
+ @reporters << Lacerda.validate_reporter(r)
10
+ end
11
+ end
12
+
13
+ methods = Lacerda::Reporter.instance_methods - Object.instance_methods
14
+ methods.each do |method|
15
+ define_method method do |*args|
16
+ send_args = [method, args].flatten
17
+ @reporters.each do |r|
18
+ r.send(*send_args)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ #methods = Lacerda::Reporter.instance_methods - Object.instance_methods
27
+ #methods.each do |method|
28
+ # Lacerda::Reporters::Multi.send(:define_method, method) do |*args|
29
+ # send_args = [method, args].flatten.compact
30
+ # @reporters.each do |r|
31
+ # r.send(*[method, args].flatten)
32
+ # end
33
+ # end
34
+ #end
@@ -0,0 +1,6 @@
1
+ module Lacerda
2
+ module Reporters
3
+ class RSpec < Lacerda::Reporter
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,45 @@
1
+ # coding: utf-8
2
+ module Lacerda
3
+ module Reporters
4
+ class Stdout < Lacerda::Reporter
5
+ def initialize(options = {})
6
+ @verbose = options.fetch(:verbose, true)
7
+ @io = options.fetch(:output, $stdout)
8
+ end
9
+
10
+ def check_publishing
11
+ end
12
+
13
+ def check_publisher(publisher)
14
+ @io.print "\n#{publisher.name.camelize} satisfies: " if @verbose
15
+ end
16
+
17
+ def consume_specification_satisfied(consumer, is_valid)
18
+ if is_valid
19
+ @io.print "#{consumer.name.camelize.green} " if @verbose
20
+ else
21
+ @io.print "#{consumer.name.camelize.red} " if @verbose
22
+ end
23
+ end
24
+
25
+ def check_consuming
26
+ @io.print "\n" if @verbose
27
+ end
28
+
29
+ def check_consumer(consuming_service)
30
+ end
31
+
32
+ def object_publisher_existing(consumed_object, is_published)
33
+ end
34
+
35
+ def result(errors)
36
+ if errors.blank?
37
+ @io.puts "All contracts valid 🙌".green if @verbose
38
+ else
39
+ @io.puts JSON.pretty_generate(errors)
40
+ @io.puts "#{errors.length} contract violations".red
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -1,4 +1,5 @@
1
1
  require 'active_support/core_ext/string'
2
+ require 'active_support/core_ext/object/try'
2
3
  require 'blumquist'
3
4
  require 'lacerda/service/error'
4
5
 
@@ -35,24 +36,20 @@ module Lacerda
35
36
  @publish.objects
36
37
  end
37
38
 
38
- def satisfies?(service)
39
- @publish.satisfies?(service)
39
+ def satisfies?(service, reporter = nil)
40
+ Lacerda.validate_reporter(reporter)
41
+ @publish.satisfies?(service, reporter)
40
42
  end
41
43
 
42
44
  def satisfies_consumers?(options = {})
43
- verbose = options.fetch(:verbose, false)
45
+ reporter = Lacerda.validate_reporter(options.fetch(:reporter, nil))
46
+
44
47
  @errors = {}
45
- print "#{name.camelize} satisfies: " if verbose
46
48
  consumers.each do |consumer|
47
- @publish.satisfies?(consumer)
48
- if @publish.errors.empty?
49
- print "#{consumer.name.camelize.green} "if verbose
50
- next
51
- end
52
- print "#{consumer.name.camelize.red} "if verbose
49
+ @publish.satisfies?(consumer, reporter)
50
+ next if @publish.errors.empty?
53
51
  @errors["#{name} -> #{consumer.name}"] = @publish.errors
54
52
  end
55
- print "\n" if verbose
56
53
  @errors.empty?
57
54
  end
58
55
 
@@ -1,3 +1,3 @@
1
1
  module Lacerda
2
- VERSION = '0.7.0'
2
+ VERSION = '0.8.0'
3
3
  end
data/lib/lacerda.rb CHANGED
@@ -1,13 +1,24 @@
1
- require "lacerda/conversion"
2
- require "lacerda/publish_contract"
3
- require "lacerda/consume_contract"
4
- require "lacerda/service"
5
- require "lacerda/infrastructure"
6
- require "lacerda/compare/json_schema"
1
+ require 'lacerda/conversion'
2
+ require 'lacerda/publish_contract'
3
+ require 'lacerda/consume_contract'
4
+ require 'lacerda/service'
5
+ require 'lacerda/infrastructure'
6
+ require 'lacerda/compare/json_schema'
7
+ require 'lacerda/reporter'
8
+ require 'lacerda/reporters/multi'
9
+ require 'lacerda/reporters/rspec'
10
+ require 'lacerda/reporters/stdout'
7
11
 
8
12
  module Lacerda
9
13
  SCOPE_SEPARATOR = '::'
10
14
 
15
+ def self.validate_reporter(reporter)
16
+ return Lacerda::Reporters::MultiReporter.new(reporter) if reporter.is_a?(Array)
17
+ return reporter unless reporter
18
+ return reporter if reporter.class <= Lacerda::Reporter
19
+ raise "reporter must inherit from Lacerda::Reporter, but #{reporter.class.name} doesn't"
20
+ end
21
+
11
22
  # An underscore that doesn't turn :: into /
12
23
  def self.underscore(string)
13
24
  string.gsub(/#{SCOPE_SEPARATOR}/, ':')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lacerda
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jannis Hermanns
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-30 00:00:00.000000000 Z
11
+ date: 2015-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -224,6 +224,10 @@ files:
224
224
  - lib/lacerda/object_description.rb
225
225
  - lib/lacerda/publish_contract.rb
226
226
  - lib/lacerda/published_object.rb
227
+ - lib/lacerda/reporter.rb
228
+ - lib/lacerda/reporters/multi.rb
229
+ - lib/lacerda/reporters/rspec.rb
230
+ - lib/lacerda/reporters/stdout.rb
227
231
  - lib/lacerda/service.rb
228
232
  - lib/lacerda/service/error.rb
229
233
  - lib/lacerda/tasks.rb