job_contracts 0.1.1 → 0.1.2

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
  SHA256:
3
- metadata.gz: 3409ea614e4698241974af1291cac6b6e2fc0cf75c45af5d7d5ea61cde545998
4
- data.tar.gz: 7a59f4f8408f9d0c7963578b411bc5425da56e7138cb35e7cd0ee938f342dc58
3
+ metadata.gz: c8f52af511321598aed75762fb9b133a2f92af32365148881b9ab5834399ed64
4
+ data.tar.gz: 8d1646b541bcbc1599b2d8a68d41d8b8e030c333d33acda8d1b5a473ce850a49
5
5
  SHA512:
6
- metadata.gz: 6e3329c2fb4ff9a4a898c44453504259b211389f8f2d57a6a6ba1a0722da414ad843030e8c1991e79ba28dfe71abedad9ef016f130ba469a5dc37c23c441572a
7
- data.tar.gz: 40be8734e8791531b7b03fde19f89697a10744ec0f77e688a091090df9a998bffd8aa3d70c95bd1e31aba024f10338a4aa7fdea712cef9f8eeaefb4beb2fbc45
6
+ metadata.gz: 4572323c6a8aa24eba91c36111fb8155f442d265eea89e041b36b6e66e3ddd1367acd1ba340cc79281b33d365d010127e993170b2cb7b54f8712004dce9e7ba4
7
+ data.tar.gz: 66d24736ad86e8f787c2a3ea53f1c24b8d6527daa9b998f00efa4471196ebc85fee8bf01118821c3c2c9ac035c65a98f236867f44cea188f33407127dbb893be
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- [![Lines of Code](http://img.shields.io/badge/lines_of_code-240-brightgreen.svg?style=flat)](http://blog.codinghorror.com/the-best-code-is-no-code-at-all/)
1
+ [![Lines of Code](http://img.shields.io/badge/lines_of_code-236-brightgreen.svg?style=flat)](http://blog.codinghorror.com/the-best-code-is-no-code-at-all/)
2
2
  [![Code Quality](https://app.codacy.com/project/badge/Grade/f604d4bc6db0474c802ef51182732488)](https://www.codacy.com/gh/hopsoft/job_contracts/dashboard?utm_source=github.com&utm_medium=referral&utm_content=hopsoft/job_contracts&utm_campaign=Badge_Grade)
3
3
  ![tests](https://github.com/hopsoft/job_contracts/actions/workflows/test.yml/badge.svg)
4
4
 
@@ -75,11 +75,5 @@ module JobContracts
75
75
  def contract_breached!
76
76
  # noop / override in job subclasses
77
77
  end
78
-
79
- def on_contract_breach(contract)
80
- breached_contracts << contract
81
- method = self.class.on_contract_breach_callback
82
- method.is_a?(Proc) ? method.call(contract) : send(method.to_s, contract)
83
- end
84
78
  end
85
79
  end
@@ -1,11 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "observer"
4
-
5
3
  module JobContracts
6
4
  class Contract
7
- include Observable
8
-
9
5
  attr_reader :trigger, :queues
10
6
 
11
7
  def initialize(trigger: :after, halt: false, queues: [], expected: {})
@@ -32,11 +28,9 @@ module JobContracts
32
28
  # NOTE: subclasses should update `actual`, set `satisfied`, and call `super`
33
29
  def enforce!(contractable)
34
30
  return unless should_enforce?(contractable)
35
- add_observer contractable, :on_contract_breach
36
- changed if breached?
37
- notify_observers self
38
- ensure
39
- delete_observer contractable
31
+ return if satisfied?
32
+ contractable.breached_contracts << self
33
+ invoke_contract_breach_callback contractable
40
34
  end
41
35
 
42
36
  def satisfied?
@@ -73,5 +67,11 @@ module JobContracts
73
67
  protected
74
68
 
75
69
  attr_accessor :satisfied
70
+
71
+ def invoke_contract_breach_callback(contractable)
72
+ callback = contractable.class.on_contract_breach_callback
73
+ callback = contractable.method(callback.to_sym) unless callback.is_a?(Proc)
74
+ callback.call self
75
+ end
76
76
  end
77
77
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JobContracts
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: job_contracts
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Hopkins
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: standard
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 1.10.0
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 1.10.0
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: magic_frozen_string_literal
57
57
  requirement: !ruby/object:Gem::Requirement