moped_mapping 0.0.2 → 0.0.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: 9914d0817e9fd1c72047906175ef4c94ee22d21e
4
- data.tar.gz: ebe492719c88fcfa2e3994701e661adb1a95ef72
3
+ metadata.gz: d5540e7bc213fbc26a538c5e82d2d32ce7caa4a4
4
+ data.tar.gz: caa85807755e177a26ea19543d2b93dc7b6ad4f8
5
5
  SHA512:
6
- metadata.gz: 193749ea662a6afac1cdc44bcc5cd1f3236f559f9438afc9eb5f7b7fb6d16690126066117721f18dc0764c916e83f6c8542d5e193d9dbe19decdacca0ead329e
7
- data.tar.gz: 067a2b33d1f6d28b72fd8ea7567206b82907e741a8c387530ff9e1b21d52515c396396ea13cbb64a2b1642bbdea37b329d334c92d07175ff06e5cec2dc9ac510
6
+ metadata.gz: 6d39d0a78aa0a5ee1705c2836f280651a7cb2bb03b201bf555c01ef18fd2a362cb6c0955bdc74786a36714b7a708c6168cd1e0214e602341b866b22c500cc573
7
+ data.tar.gz: 3dc7b612454fa56b99197ceb2c135cad6100622e1a1765a6d87bc12c6e93d6dd30b557d3ab8397dac05121f7311e65f741b49440b5003af76dfad0230d663558
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  require "moped_mapping/version"
2
3
 
3
4
  require 'moped'
@@ -38,6 +39,20 @@ module MopedMapping
38
39
  result
39
40
  end
40
41
 
42
+ # mainスレッド以外からmainスレッドのデータを書き換えるときに使用します
43
+ def update_main_collection_map(db_name, mapping)
44
+ Mutex.new.synchronize do
45
+ mt = Thread.main
46
+ mt[:MopedMapping_db_collection_map] ||= {}
47
+ mt[:MopedMapping_db_collection_map][db_name] = mapping
48
+ ct = Thread.current
49
+ unless ct == mt
50
+ ct[:MopedMapping_db_collection_map] ||= {}
51
+ ct[:MopedMapping_db_collection_map][db_name] = mapping
52
+ end
53
+ end
54
+ end
55
+
41
56
  def mapped_name(database, collection)
42
57
  return collection unless MopedMapping.enabled
43
58
  mapping = db_collection_map[database]
@@ -1,3 +1,3 @@
1
1
  module MopedMapping
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -82,8 +82,60 @@ describe MopedMapping do
82
82
  col.find.count.should == 3
83
83
  end
84
84
  end
85
+
86
+ it "update thread local mapping" do
87
+ MopedMapping.collection_map(@database_name,{"items" => "items@2" })
88
+ MopedMapping.enable
89
+
90
+ expect(MopedMapping.db_collection_map[@database_name]["items"]).to eq "items@2"
91
+
92
+ t = Thread.new do
93
+ expect(MopedMapping.db_collection_map[@database_name]["items"]).to eq "items@2"
94
+ MopedMapping.collection_map(@database_name, {"items" => "items@3"})
95
+ expect(MopedMapping.db_collection_map[@database_name]["items"]).to eq "items@3"
96
+ Thread.pass
97
+ end
98
+ t.join
99
+
100
+ MopedMapping.update_main_collection_map(@database_name, {"items" => "items@2"})
101
+
102
+ t = Thread.new do
103
+ MopedMapping.update_main_collection_map(@database_name, {"items" => "items@2"})
104
+ Thread.pass
105
+ end
106
+ t.join
107
+
108
+ end
109
+
85
110
  end
86
111
 
112
+ describe :update_main_collection_map do
113
+ it "update main mapping" do
114
+ MopedMapping.collection_map(@database_name,{"items" => "items@2" })
115
+ MopedMapping.enable
116
+
117
+ expect(MopedMapping.db_collection_map[@database_name]["items"]).to eq "items@2"
118
+
119
+ t = Thread.new do
120
+ expect(MopedMapping.db_collection_map[@database_name]["items"]).to eq "items@2"
121
+ MopedMapping.update_main_collection_map(@database_name, {"items" => "items@3"})
122
+ expect(MopedMapping.db_collection_map[@database_name]["items"]).to eq "items@3"
123
+ Thread.pass
124
+ end
125
+ t.join
126
+
127
+ MopedMapping.update_main_collection_map(@database_name, {"items" => "items@3"})
128
+
129
+ t = Thread.new do
130
+ MopedMapping.update_main_collection_map(@database_name, {"items" => "items@3"})
131
+ Thread.pass
132
+ end
133
+ t.join
134
+
135
+ end
136
+ end
137
+
138
+
87
139
  describe :create do
88
140
  it "actual usage" do
89
141
  MopedMapping.collection_map(@database_name,{"items" => "items@4" })
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moped_mapping
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - akima
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-05 00:00:00.000000000 Z
11
+ date: 2014-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: moped
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: 1.5.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.5.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.3'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
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
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: tengine_support
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  description: make mapping from moped collection object to MongoDB actual collection
@@ -74,7 +74,7 @@ executables: []
74
74
  extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
77
- - .gitignore
77
+ - ".gitignore"
78
78
  - Gemfile
79
79
  - LICENSE.txt
80
80
  - README.md
@@ -101,17 +101,17 @@ require_paths:
101
101
  - lib
102
102
  required_ruby_version: !ruby/object:Gem::Requirement
103
103
  requirements:
104
- - - '>='
104
+ - - ">="
105
105
  - !ruby/object:Gem::Version
106
106
  version: '0'
107
107
  required_rubygems_version: !ruby/object:Gem::Requirement
108
108
  requirements:
109
- - - '>='
109
+ - - ">="
110
110
  - !ruby/object:Gem::Version
111
111
  version: '0'
112
112
  requirements: []
113
113
  rubyforge_project:
114
- rubygems_version: 2.0.3
114
+ rubygems_version: 2.2.2
115
115
  signing_key:
116
116
  specification_version: 4
117
117
  summary: make mapping from moped collection object to MongoDB actual collection by