business_time 0.9.2 → 0.9.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: ec9aa7a308caa41ed4307f45ef8b798759b10a0c
4
- data.tar.gz: 1430aa8263c16efb585414432230db3861472f55
3
+ metadata.gz: 5fe356eb4f4e620e3f3db2aa9242df1c63213500
4
+ data.tar.gz: d1f662a4f576662e3f6d140970d5b2191016fda8
5
5
  SHA512:
6
- metadata.gz: 366fbc15803d7fab5a13ea85c485a62ad71c037de68322e3b662f9530ea1e261aecab5df46761391dcef13a3c408063b42633049f0aa70dc18832b5b4dab644b
7
- data.tar.gz: 2c60d5bef66eaa83b38a70a8603c0b62f1a6ea1bb6ad562acfdb3714c8db6074c3c3248790bf26c86dd56b6f3729fe469bfb64b1bcc945f22d58eee1e117d7e3
6
+ metadata.gz: 86434d31fbf26aa3372510db883266643431a449fa2980cee43e9d34198c140a560d0606d41911aa0a47e030b373eeba0442f38dad07c36a5b5113a811c97213
7
+ data.tar.gz: 5c1ae7866418a21538030ba2129698eaafb2016b5d715cd2c13e31e1739b8732ff625af6f87e48e98bbe697ea06005d74c35bfab7c8610b306f7ba7c9d0121b5
@@ -17,14 +17,14 @@ module BusinessTime
17
17
  end
18
18
 
19
19
  def after(time = Time.current)
20
- positive_days? ? calculate_after(time, @days) : calculate_before(time, -@days)
20
+ non_negative_days? ? calculate_after(time, @days) : calculate_before(time, -@days)
21
21
  end
22
22
 
23
23
  alias_method :from_now, :after
24
24
  alias_method :since, :after
25
25
 
26
26
  def before(time = Time.current)
27
- positive_days? ? calculate_before(time, @days) : calculate_after(time, -@days)
27
+ non_negative_days? ? calculate_before(time, @days) : calculate_after(time, -@days)
28
28
  end
29
29
 
30
30
  alias_method :ago, :before
@@ -32,8 +32,8 @@ module BusinessTime
32
32
 
33
33
  private
34
34
 
35
- def positive_days?
36
- @days > 0
35
+ def non_negative_days?
36
+ @days >= 0
37
37
  end
38
38
 
39
39
  def calculate_after(time, days)
@@ -24,18 +24,18 @@ module BusinessTime
24
24
  end
25
25
 
26
26
  def after(time)
27
- positive_hours? ? calculate_after(time, @hours) : calculate_before(time, -@hours)
27
+ non_negative_hours? ? calculate_after(time, @hours) : calculate_before(time, -@hours)
28
28
  end
29
29
  alias_method :since, :after
30
30
 
31
31
  def before(time)
32
- positive_hours? ? calculate_before(time, @hours) : calculate_after(time, -@hours)
32
+ non_negative_hours? ? calculate_before(time, @hours) : calculate_after(time, -@hours)
33
33
  end
34
34
 
35
35
  private
36
36
 
37
- def positive_hours?
38
- @hours > 0
37
+ def non_negative_hours?
38
+ @hours >= 0
39
39
  end
40
40
 
41
41
  def calculate_after(time, hours)
@@ -47,15 +47,19 @@ module BusinessTime
47
47
  end
48
48
 
49
49
  def local_config
50
- Thread.current[:business_time_local_config]
50
+ local_config_stack.last
51
51
  end
52
52
 
53
53
  def local_config=(config)
54
- Thread.current[:business_time_local_config] = config
54
+ local_config_stack.last.replace(config)
55
+ end
56
+
57
+ def local_config_stack
58
+ Thread.current[:business_time_local_config] ||= []
55
59
  end
56
60
 
57
61
  def local_config?
58
- !local_config.nil?
62
+ !local_config_stack.empty?
59
63
  end
60
64
 
61
65
  def threadsafe_cattr_accessor(name)
@@ -173,11 +177,11 @@ module BusinessTime
173
177
  end
174
178
 
175
179
  def with(config)
176
- self.local_config = config().dup
180
+ local_config_stack.push(config().dup)
177
181
  config.each { |k,v| send("#{k}=", v) } # calculations are done on setting
178
182
  yield
179
183
  ensure
180
- self.local_config = nil
184
+ local_config_stack.pop
181
185
  end
182
186
 
183
187
  def default_config
@@ -196,8 +200,8 @@ module BusinessTime
196
200
  end
197
201
 
198
202
  def reset
199
- self.config = default_config
200
- self.local_config = nil
203
+ local_config_stack.clear
204
+ self.config = default_config
201
205
  end
202
206
 
203
207
  def deep_dup(object)
@@ -1,3 +1,3 @@
1
1
  module BusinessTime
2
- VERSION = "0.9.2"
2
+ VERSION = "0.9.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: business_time
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - bokmann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-07 00:00:00.000000000 Z
11
+ date: 2017-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -138,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
138
  version: '0'
139
139
  requirements: []
140
140
  rubyforge_project:
141
- rubygems_version: 2.6.11
141
+ rubygems_version: 2.6.13
142
142
  signing_key:
143
143
  specification_version: 4
144
144
  summary: Support for doing time math in business hours and days