working_hours 1.0.4 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1b22e4d023c26a46743000425945952ab1bab9fd
4
- data.tar.gz: cbed8ec547a77301003e9dc7ed0686c08f2cac46
3
+ metadata.gz: 4b1729fae716e9632d6944229a25e12b76c4acd3
4
+ data.tar.gz: bf9c3b93eeee75439bbc09b05ecb7db36465ca0b
5
5
  SHA512:
6
- metadata.gz: a63290c01a8c6f78782a7abc917b655e16d97c115f44c1c3a075cfe067ddc8a68a4df7fc609d10ba81beb471e963032b7491df872b0ea372e8585377832b938b
7
- data.tar.gz: a65bebd4a98cd33caccd717924166bbc89057f7b0800385cca6902ef2a76a1d5367cda365de1926000f37816f028fbb728154db5ae1d9ac08fe43050e279152f
6
+ metadata.gz: c545c3b569235af36415d087c42eb54a9137f0bcc6c27a5a17dcfd85ac5efcd9440b6b671dc69193329c721c66b2b76a53767b0f9c9c92cb1ac68d4d6fc49e5b
7
+ data.tar.gz: a1a2b0e842150465f06d7f6c89475f509416b83e86ea41a4dcedac8c55cff11bcac1d7f01fcc828d6c8fd600c0ab8660b9a65326fa75046eda1fdaf5c8aed78a
data/.gitignore CHANGED
File without changes
data/.rspec CHANGED
File without changes
data/CHANGELOG.md CHANGED
@@ -1,10 +1,17 @@
1
1
  # Unreleased
2
2
 
3
- [Compare master with v1.0.3](https://github.com/intrepidd/working_hours/compare/v1.0.3...master)
3
+ [Compare master with v1.1.0](https://github.com/intrepidd/working_hours/compare/v1.1.0...master)
4
+
5
+ # v1.1.0
6
+ * Config set globally is now properly inherited in new threads. This fixes the issue when setting the config once in an initializer won't work in threaded web servers.
7
+
8
+ _03/04/2015_
4
9
 
5
10
  # v1.0.4
6
11
  * Fixed a nasty stack level too deep error on DateTime#+ and DateTime#- (thanks @jlanatta)
7
12
 
13
+ _27/03/2015_
14
+
8
15
  # v1.0.3
9
16
 
10
17
  * Relax configuration input formats - [#10](https://github.com/Intrepidd/working_hours/pull/10)
data/Gemfile CHANGED
File without changes
data/LICENSE.txt CHANGED
File without changes
data/README.md CHANGED
@@ -63,7 +63,7 @@ WorkingHours.return_to_working_time(Time.utc(2014, 8, 4, 7, 16)) # => Fri, 01 Au
63
63
 
64
64
  ## Configuration
65
65
 
66
- The working hours configuration is thread local and consists of a hash defining working periods for each day, a time zone and a list of days off.
66
+ The working hours configuration is thread safe and consists of a hash defining working periods for each day, a time zone and a list of days off. You can set it once, for example in a initializer for rails:
67
67
 
68
68
  ```ruby
69
69
  # Configure working hours
@@ -82,7 +82,7 @@ WorkingHours::Config.time_zone = 'Paris'
82
82
  WorkingHours::Config.holidays = [Date.new(2014, 12, 31)]
83
83
  ```
84
84
 
85
- Alternatively, you can apply a particular config in a block with the ``with_config`` method :
85
+ Or you can set it for the duration of a block with the `with_config` method, this is particularly useful with `around_filter`:
86
86
 
87
87
  ```ruby
88
88
  WorkingHours::Config.with_config(working_hours: {mon:{'09:00' => '18:00'}}, holidays: [], time_zone: 'Paris') do
data/Rakefile CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
data/lib/working_hours.rb CHANGED
File without changes
@@ -17,6 +17,7 @@ module WorkingHours
17
17
  def working_hours=(val)
18
18
  validate_working_hours! val
19
19
  config[:working_hours] = val
20
+ global_config[:working_hours] = val
20
21
  config.delete :precompiled
21
22
  end
22
23
 
@@ -27,6 +28,7 @@ module WorkingHours
27
28
  def holidays=(val)
28
29
  validate_holidays! val
29
30
  config[:holidays] = val
31
+ global_config[:holidays] = val
30
32
  config.delete :precompiled
31
33
  end
32
34
 
@@ -62,6 +64,7 @@ module WorkingHours
62
64
  def time_zone=(val)
63
65
  zone = validate_time_zone! val
64
66
  config[:time_zone] = zone
67
+ global_config[:time_zone] = val
65
68
  config.delete :precompiled
66
69
  end
67
70
 
@@ -86,7 +89,11 @@ module WorkingHours
86
89
  private
87
90
 
88
91
  def config
89
- Thread.current[:working_hours] ||= default_config
92
+ Thread.current[:working_hours] ||= global_config
93
+ end
94
+
95
+ def global_config
96
+ @@global_config ||= default_config
90
97
  end
91
98
 
92
99
  def default_config
File without changes
File without changes
File without changes
@@ -1,3 +1,3 @@
1
1
  module WorkingHours
2
- VERSION = "1.0.4"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -26,6 +26,13 @@ describe WorkingHours::Config do
26
26
  }.not_to change { WorkingHours::Config.working_hours }
27
27
  end
28
28
 
29
+ it 'is initialized from last known global config' do
30
+ WorkingHours::Config.working_hours = {:mon => {'08:00' => '14:00'}}
31
+ Thread.new {
32
+ expect(WorkingHours::Config.working_hours).to match :mon => {'08:00' => '14:00'}
33
+ }.join
34
+ end
35
+
29
36
  it 'should have a key for each week day' do
30
37
  [:mon, :tue, :wed, :thu, :fri].each do |d|
31
38
  expect(config[d]).to be_kind_of(Hash)
@@ -137,6 +144,13 @@ describe WorkingHours::Config do
137
144
  }.to change { WorkingHours::Config.precompiled[:holidays] }.by(Set.new([Date.today]))
138
145
  end
139
146
 
147
+ it 'is initialized from last known global config' do
148
+ WorkingHours::Config.holidays = [Date.today]
149
+ Thread.new {
150
+ expect(WorkingHours::Config.holidays).to eq [Date.today]
151
+ }.join
152
+ end
153
+
140
154
  describe 'validation' do
141
155
  it 'rejects types that cannot be converted into an array' do
142
156
  expect {
@@ -178,6 +192,13 @@ describe WorkingHours::Config do
178
192
  expect(config).to eq(ActiveSupport::TimeZone['Tokyo'])
179
193
  end
180
194
 
195
+ it 'is initialized from last known global config' do
196
+ WorkingHours::Config.time_zone = ActiveSupport::TimeZone['Tokyo']
197
+ Thread.new {
198
+ expect(WorkingHours::Config.time_zone).to eq ActiveSupport::TimeZone['Tokyo']
199
+ }.join
200
+ end
201
+
181
202
  it "recomputes precompiled when modified" do
182
203
  expect {
183
204
  WorkingHours::Config.time_zone.instance_variable_set(:@name, 'Bordeaux')
File without changes
File without changes
File without changes
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: working_hours
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrien Jarthon
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-03-27 00:00:00.000000000 Z
12
+ date: 2015-04-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -154,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
154
  version: '0'
155
155
  requirements: []
156
156
  rubyforge_project:
157
- rubygems_version: 2.4.6
157
+ rubygems_version: 2.2.2
158
158
  signing_key:
159
159
  specification_version: 4
160
160
  summary: time calculation with working hours
@@ -167,3 +167,4 @@ test_files:
167
167
  - spec/working_hours/duration_proxy_spec.rb
168
168
  - spec/working_hours/duration_spec.rb
169
169
  - spec/working_hours_spec.rb
170
+ has_rdoc: