opto 1.8.2 → 1.8.3

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: f08a0ec227631377b328f07f87e3b0ff2f1e2def
4
- data.tar.gz: 3af3a7c0077be8a24f304789a14dfbc970162e0e
3
+ metadata.gz: 2d154fe92a61aa8299e7275cb82e22e659becbae
4
+ data.tar.gz: 572aff6816d0aaf364482f0543c6a68a30a5a981
5
5
  SHA512:
6
- metadata.gz: eb8f310f22ded339e110e98ca00d01f4f2922307ca3697b7c1dd4e989183fd160a3ecd123238d6abe0a9ca1d72981e001e1eb2ae2050f69cdb51ef76a35a81c7
7
- data.tar.gz: c6472dfea318ad51b7c85148d66b63580216266d08fe0250ff1f1638a11033272635c47480bd872eb40af19c9b573507ad83a4c6c4d9a8ea758a8a2557a2d911
6
+ metadata.gz: ef4277e6893c6cc03226c982821c98079eb8154562f59405d7f0493b5a719dc1c105e8765791afa6f0e3c3bb881f399c5101003e09e200162341ad8b6f0d4ef0
7
+ data.tar.gz: 5b6bb2f4d14ade307209de3a83e2e97f45ab4cfd3c9f904388f100ffcdde2d8b5d7f85fa8a25fe216321d0971495db0451225d599b72fdc6828e91ef1c307a47
data/lib/opto/option.rb CHANGED
@@ -199,13 +199,11 @@ module Opto
199
199
  def resolve
200
200
  resolvers.each do |resolver|
201
201
  begin
202
- resolver.respond_to?(:before) && resolver.before(self)
203
- result = resolver.resolve
204
- resolver.respond_to?(:after) && resolver.after(self)
202
+ result = resolver.try_resolve
205
203
  rescue StandardError => ex
206
204
  raise ex, "Resolver '#{resolver.origin}' for '#{name}' : #{ex.message}"
207
205
  end
208
- if result
206
+ unless result.nil?
209
207
  @origin = resolver.origin
210
208
  return result
211
209
  end
data/lib/opto/resolver.rb CHANGED
@@ -43,6 +43,28 @@ module Opto
43
43
  def initialize(hint = nil, option = nil)
44
44
  @hint = hint
45
45
  @option = option
46
+ @tried = false
47
+ end
48
+
49
+ def tried?
50
+ !!@tried
51
+ end
52
+
53
+ def set_tried
54
+ @tried = true
55
+ end
56
+
57
+ def reset_tried
58
+ @tried = false
59
+ end
60
+
61
+ def try_resolve
62
+ return nil if tried?
63
+ set_tried
64
+ self.respond_to?(:before) && self.before
65
+ result = resolve
66
+ self.respond_to?(:after) && self.after
67
+ result
46
68
  end
47
69
 
48
70
  # This is a "base" class, you're supposed to inherit from this in your resolver and define a #resolve method.
@@ -79,6 +79,10 @@ module Opto
79
79
  matching_condition = conditions.find {|c| c.true? }
80
80
  matching_condition.result
81
81
  end
82
+
83
+ def after
84
+ reset_tried # conditional value can change if some of the depending variables change values
85
+ end
82
86
  end
83
87
  end
84
88
  end
@@ -27,6 +27,10 @@ module Opto
27
27
  raise TypeError, "Syntax error: '#{interpolated_hint}' does not look like a number or a calculation"
28
28
  end
29
29
  end
30
+
31
+ def after
32
+ reset_tried
33
+ end
30
34
  end
31
35
  end
32
36
  end
@@ -25,6 +25,10 @@ module Opto
25
25
  option.value_of(var)
26
26
  end
27
27
  end
28
+
29
+ def after
30
+ reset_tried
31
+ end
28
32
  end
29
33
  end
30
34
  end
data/lib/opto/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Opto
2
- VERSION = "1.8.2"
2
+ VERSION = "1.8.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opto
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.2
4
+ version: 1.8.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kimmo Lehto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-06 00:00:00.000000000 Z
11
+ date: 2017-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler