yaoc 0.0.12 → 0.0.13
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 +4 -4
- data/lib/yaoc.rb +2 -3
- data/lib/yaoc/mapper_registry.rb +2 -2
- data/lib/yaoc/version.rb +1 -1
- data/spec/unit/lib/yaoc/mapper_registry_spec.rb +1 -1
- data/yaoc.gemspec +1 -0
- metadata +16 -13
- data/lib/yaoc/helper/scope.rb +0 -34
- data/lib/yaoc/helper/thread_global_storage.rb +0 -56
- data/lib/yaoc/helper/thread_local_storage.rb +0 -37
- data/spec/integration/lib/yaoc/helper/scope_spec.rb +0 -14
- data/spec/unit/lib/yaoc/helper/scope_spec.rb +0 -57
- data/spec/unit/lib/yaoc/helper/thread_global_storage_spec.rb +0 -49
- data/spec/unit/lib/yaoc/helper/thread_local_storage_spec.rb +0 -50
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d41454b6c8f8f911daba762a29d4d4447f826a6
|
4
|
+
data.tar.gz: cb825e83ede21f8f54033564bbc7864627a580d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60701029b179a8c63f027c07344eafddafcdda486141c0abe5d036b787a5c31aae4a99fa0e1317bdc3a33e866073d54a415f5e079c96266d005a435dc2722d11
|
7
|
+
data.tar.gz: 0663cc0309770642fc542b246175b4881d43ef77d2ceeecd7f620a2ca7326fb1ba5bb3fa1fd650af64e304eda02b2b383d5b9090aec1bb4f29da8de54a717f82
|
data/lib/yaoc.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
require "yaoc/version"
|
2
2
|
|
3
|
+
require 'scoped_storage'
|
4
|
+
|
3
5
|
require 'yaoc/helper/struct_hash_constructor'
|
4
6
|
require 'yaoc/helper/to_proc_delegator'
|
5
|
-
require 'yaoc/helper/thread_local_storage'
|
6
|
-
require 'yaoc/helper/thread_global_storage'
|
7
|
-
require 'yaoc/helper/scope'
|
8
7
|
|
9
8
|
require 'yaoc/mapper_registry'
|
10
9
|
require 'yaoc/mapping_base'
|
data/lib/yaoc/mapper_registry.rb
CHANGED
@@ -3,11 +3,11 @@ module Yaoc
|
|
3
3
|
module_function
|
4
4
|
|
5
5
|
def scope_storage(new_storage)
|
6
|
-
@scope =
|
6
|
+
@scope = ScopedStorage::Scope.new("mappings", new_storage)
|
7
7
|
end
|
8
8
|
|
9
9
|
def scope
|
10
|
-
@scope ||=
|
10
|
+
@scope ||= ScopedStorage::Scope.new("mappings")
|
11
11
|
end
|
12
12
|
|
13
13
|
def add(key, mapper)
|
data/lib/yaoc/version.rb
CHANGED
@@ -21,7 +21,7 @@ describe Yaoc::MapperRegistry do
|
|
21
21
|
|
22
22
|
describe '.scope_storage' do
|
23
23
|
it 'supports the change of scope storage' do
|
24
|
-
expect {subject.scope_storage(
|
24
|
+
expect {subject.scope_storage(ScopedStorage::ThreadLocalStorage)}.not_to raise_error
|
25
25
|
end
|
26
26
|
|
27
27
|
end
|
data/yaoc.gemspec
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yaoc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dieter Späth
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: scoped_storage
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -215,10 +229,7 @@ files:
|
|
215
229
|
- examples/all_examples.rb
|
216
230
|
- lib/yaoc.rb
|
217
231
|
- lib/yaoc/converter_builder.rb
|
218
|
-
- lib/yaoc/helper/scope.rb
|
219
232
|
- lib/yaoc/helper/struct_hash_constructor.rb
|
220
|
-
- lib/yaoc/helper/thread_global_storage.rb
|
221
|
-
- lib/yaoc/helper/thread_local_storage.rb
|
222
233
|
- lib/yaoc/helper/to_proc_delegator.rb
|
223
234
|
- lib/yaoc/many_to_one_mapper_chain.rb
|
224
235
|
- lib/yaoc/mapper_registry.rb
|
@@ -239,14 +250,10 @@ files:
|
|
239
250
|
- spec/acceptance/map_to_objects_with_lazy_loading_spec.rb
|
240
251
|
- spec/acceptance/map_to_objects_with_positional_constructors_spec.rb
|
241
252
|
- spec/integration/lib/yaoc/converter_builder_spec.rb
|
242
|
-
- spec/integration/lib/yaoc/helper/scope_spec.rb
|
243
253
|
- spec/spec_helper.rb
|
244
254
|
- spec/support/feature.rb
|
245
255
|
- spec/unit/lib/yaoc/converter_builder_spec.rb
|
246
|
-
- spec/unit/lib/yaoc/helper/scope_spec.rb
|
247
256
|
- spec/unit/lib/yaoc/helper/struct_hash_constructor_spec.rb
|
248
|
-
- spec/unit/lib/yaoc/helper/thread_global_storage_spec.rb
|
249
|
-
- spec/unit/lib/yaoc/helper/thread_local_storage_spec.rb
|
250
257
|
- spec/unit/lib/yaoc/helper/to_proc_delegator_spec.rb
|
251
258
|
- spec/unit/lib/yaoc/many_to_one_mapper_chain_spec.rb
|
252
259
|
- spec/unit/lib/yaoc/mapper_registry_spec.rb
|
@@ -292,14 +299,10 @@ test_files:
|
|
292
299
|
- spec/acceptance/map_to_objects_with_lazy_loading_spec.rb
|
293
300
|
- spec/acceptance/map_to_objects_with_positional_constructors_spec.rb
|
294
301
|
- spec/integration/lib/yaoc/converter_builder_spec.rb
|
295
|
-
- spec/integration/lib/yaoc/helper/scope_spec.rb
|
296
302
|
- spec/spec_helper.rb
|
297
303
|
- spec/support/feature.rb
|
298
304
|
- spec/unit/lib/yaoc/converter_builder_spec.rb
|
299
|
-
- spec/unit/lib/yaoc/helper/scope_spec.rb
|
300
305
|
- spec/unit/lib/yaoc/helper/struct_hash_constructor_spec.rb
|
301
|
-
- spec/unit/lib/yaoc/helper/thread_global_storage_spec.rb
|
302
|
-
- spec/unit/lib/yaoc/helper/thread_local_storage_spec.rb
|
303
306
|
- spec/unit/lib/yaoc/helper/to_proc_delegator_spec.rb
|
304
307
|
- spec/unit/lib/yaoc/many_to_one_mapper_chain_spec.rb
|
305
308
|
- spec/unit/lib/yaoc/mapper_registry_spec.rb
|
data/lib/yaoc/helper/scope.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
module Yaoc
|
2
|
-
module Helper
|
3
|
-
class Scope
|
4
|
-
|
5
|
-
attr_accessor :scope_name, :storage_source
|
6
|
-
|
7
|
-
def initialize(scope_name="default", storage_source=ThreadGlobalStorage)
|
8
|
-
self.scope_name = scope_name
|
9
|
-
self.storage_source = storage_source
|
10
|
-
end
|
11
|
-
|
12
|
-
def storage
|
13
|
-
storage_source.for(scope_name)
|
14
|
-
end
|
15
|
-
|
16
|
-
def []=(key, value)
|
17
|
-
self.storage[key]=value
|
18
|
-
end
|
19
|
-
|
20
|
-
def [](key)
|
21
|
-
self.storage[key]
|
22
|
-
end
|
23
|
-
|
24
|
-
def clear!
|
25
|
-
self.storage.clear
|
26
|
-
end
|
27
|
-
|
28
|
-
def fetch(*args, &block)
|
29
|
-
self.storage.fetch(*args, &block)
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
module Yaoc
|
2
|
-
module Helper
|
3
|
-
require 'thread'
|
4
|
-
|
5
|
-
class ThreadGlobalStorage
|
6
|
-
class << self
|
7
|
-
private :new
|
8
|
-
end
|
9
|
-
|
10
|
-
attr_accessor :data
|
11
|
-
|
12
|
-
@mutex = Mutex.new
|
13
|
-
|
14
|
-
def self.mutex
|
15
|
-
@mutex
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.for(scope_name="default")
|
19
|
-
mutex.synchronize {
|
20
|
-
@storage ||= {}
|
21
|
-
@storage[scope_name] ||= new
|
22
|
-
}
|
23
|
-
end
|
24
|
-
|
25
|
-
def initialize
|
26
|
-
self.data||={}
|
27
|
-
end
|
28
|
-
|
29
|
-
def []=(key, value)
|
30
|
-
mutex.synchronize {
|
31
|
-
self.data[key]=value
|
32
|
-
}
|
33
|
-
end
|
34
|
-
|
35
|
-
def [](key)
|
36
|
-
self.data[key]
|
37
|
-
end
|
38
|
-
|
39
|
-
def clear!
|
40
|
-
mutex.synchronize {
|
41
|
-
self.data.clear
|
42
|
-
}
|
43
|
-
end
|
44
|
-
|
45
|
-
def fetch(*args, &block)
|
46
|
-
self.data.fetch(*args, &block)
|
47
|
-
end
|
48
|
-
|
49
|
-
def mutex
|
50
|
-
self.class.mutex
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
@@ -1,37 +0,0 @@
|
|
1
|
-
module Yaoc
|
2
|
-
module Helper
|
3
|
-
class ThreadLocalStorage
|
4
|
-
class << self
|
5
|
-
private :new
|
6
|
-
end
|
7
|
-
|
8
|
-
attr_accessor :data
|
9
|
-
|
10
|
-
def self.for(scope_name="default")
|
11
|
-
Thread.current["_#{name}_#{scope_name}"] ||= new
|
12
|
-
end
|
13
|
-
|
14
|
-
def initialize
|
15
|
-
self.data||={}
|
16
|
-
end
|
17
|
-
|
18
|
-
def []=(key, value)
|
19
|
-
self.data[key]=value
|
20
|
-
end
|
21
|
-
|
22
|
-
def [](key)
|
23
|
-
self.data[key]
|
24
|
-
end
|
25
|
-
|
26
|
-
def clear!
|
27
|
-
self.data.clear
|
28
|
-
end
|
29
|
-
|
30
|
-
def fetch(*args, &block)
|
31
|
-
self.data.fetch(*args, &block)
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
@@ -1,57 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Yaoc::Helper::Scope do
|
4
|
-
class DummyStorage
|
5
|
-
def initialize(new_data)
|
6
|
-
@data = new_data
|
7
|
-
end
|
8
|
-
|
9
|
-
def for(*args)
|
10
|
-
data
|
11
|
-
end
|
12
|
-
|
13
|
-
def data
|
14
|
-
@data
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
subject{
|
20
|
-
Yaoc::Helper::Scope.new("default", DummyStorage.new(data_double))
|
21
|
-
}
|
22
|
-
|
23
|
-
let(:data_double){
|
24
|
-
{}
|
25
|
-
}
|
26
|
-
|
27
|
-
describe '#[]=' do
|
28
|
-
it 'let me set values' do
|
29
|
-
subject['new_value'] = 123
|
30
|
-
expect(subject.fetch('new_value')).to eq 123
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
describe '#[]' do
|
35
|
-
it 'let me fetch values' do
|
36
|
-
subject['new_value'] = 123
|
37
|
-
expect(subject['new_value']).to eq 123
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe '#clear!' do
|
42
|
-
it 'let me fetch values' do
|
43
|
-
subject['new_value'] = 123
|
44
|
-
subject.clear!
|
45
|
-
expect(subject['new_value']).to be_nil
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
describe '#fetch' do
|
50
|
-
it 'works like hash fetch' do
|
51
|
-
fetched_value = subject.fetch('some_key'){|*args| args}
|
52
|
-
|
53
|
-
expect(fetched_value).to eq ['some_key']
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Yaoc::Helper::ThreadGlobalStorage do
|
4
|
-
subject{
|
5
|
-
Yaoc::Helper::ThreadGlobalStorage
|
6
|
-
}
|
7
|
-
|
8
|
-
let(:storage){
|
9
|
-
subject.for
|
10
|
-
}
|
11
|
-
|
12
|
-
describe '.for' do
|
13
|
-
it 'creates a new object for all threads' do
|
14
|
-
subject.for
|
15
|
-
|
16
|
-
threat_one_object_id = nil
|
17
|
-
threat_two_object_id = nil
|
18
|
-
threats = []
|
19
|
-
|
20
|
-
threats << Thread.new{
|
21
|
-
threat_one_object_id = Yaoc::Helper::ThreadLocalStorage.for
|
22
|
-
}
|
23
|
-
|
24
|
-
threats << Thread.new{
|
25
|
-
threat_two_object_id = Yaoc::Helper::ThreadLocalStorage.for
|
26
|
-
}
|
27
|
-
|
28
|
-
threats.each &:join
|
29
|
-
|
30
|
-
expect(threat_one_object_id).not_to eq threat_two_object_id
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'supports naming different scopes' do
|
34
|
-
second_scope = subject.for 'the second scope'
|
35
|
-
expect(second_scope.object_id).not_to be subject.for.object_id
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'supports hash like accessors' do
|
40
|
-
storage['key'] = 1
|
41
|
-
expect(storage['key']).to eq 1
|
42
|
-
expect(storage.fetch 'key').to eq 1
|
43
|
-
|
44
|
-
storage.clear!
|
45
|
-
|
46
|
-
expect(storage['key']).to be_nil
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Yaoc::Helper::ThreadLocalStorage do
|
4
|
-
subject{
|
5
|
-
Yaoc::Helper::ThreadLocalStorage
|
6
|
-
}
|
7
|
-
|
8
|
-
let(:storage){
|
9
|
-
subject.for
|
10
|
-
}
|
11
|
-
|
12
|
-
describe '.for' do
|
13
|
-
it 'creates a new object for every thread' do
|
14
|
-
subject.for
|
15
|
-
|
16
|
-
threat_one_object_id = nil
|
17
|
-
threat_two_object_id = nil
|
18
|
-
threats = []
|
19
|
-
|
20
|
-
threats << Thread.new{
|
21
|
-
threat_one_object_id = Yaoc::Helper::ThreadLocalStorage.for
|
22
|
-
}
|
23
|
-
|
24
|
-
threats << Thread.new{
|
25
|
-
threat_two_object_id = Yaoc::Helper::ThreadLocalStorage.for
|
26
|
-
}
|
27
|
-
|
28
|
-
threats.each &:join
|
29
|
-
|
30
|
-
expect(threat_one_object_id).not_to eq threat_two_object_id
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'supports naming different scopes' do
|
34
|
-
second_scope = subject.for 'the second scope'
|
35
|
-
expect(second_scope.object_id).not_to be subject.for.object_id
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'supports hash like accessors' do
|
40
|
-
storage['key'] = 1
|
41
|
-
expect(storage['key']).to eq 1
|
42
|
-
expect(storage.fetch 'key').to eq 1
|
43
|
-
|
44
|
-
storage.clear!
|
45
|
-
|
46
|
-
expect(storage['key']).to be_nil
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|