frozen_record 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/frozen_record/base.rb +24 -2
- data/lib/frozen_record/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ea4f7773d19e5117d8b6f23c0d084f69d9b9536
|
4
|
+
data.tar.gz: 55b940e5665ae50fbde6f2a39ea5cd3ef5a441f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0bd1f71685d2bac36df3311bf9b8d97697d755eb910a7c7903a64add5543f51b98d975f99813c4c9aa8d2df7c8968f040e28f5478af061469fb964282e06d08
|
7
|
+
data.tar.gz: bc8c7766b4100563913f824bd6cb2e95e75439eb8a20cec2ad204195e48b1c8916dc17fcc61f7e9a81a35e0c5b5eef6095477893cf0cd573dc950f1c9a42526f
|
data/lib/frozen_record/base.rb
CHANGED
@@ -18,15 +18,33 @@ module FrozenRecord
|
|
18
18
|
|
19
19
|
attribute_method_suffix '?'
|
20
20
|
|
21
|
+
class ThreadSafeStorage
|
22
|
+
|
23
|
+
def initialize(key)
|
24
|
+
@thread_key = key
|
25
|
+
end
|
26
|
+
|
27
|
+
def [](key)
|
28
|
+
Thread.current[@thread_key] ||= {}
|
29
|
+
Thread.current[@thread_key][key]
|
30
|
+
end
|
31
|
+
|
32
|
+
def []=(key, value)
|
33
|
+
Thread.current[@thread_key] ||= {}
|
34
|
+
Thread.current[@thread_key][key] = value
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
21
39
|
class << self
|
22
40
|
|
23
41
|
def current_scope
|
24
|
-
|
42
|
+
store[:scope] ||= Scope.new(self, load_records)
|
25
43
|
end
|
26
44
|
alias_method :all, :current_scope
|
27
45
|
|
28
46
|
def current_scope=(scope)
|
29
|
-
|
47
|
+
store[:scope] = scope
|
30
48
|
end
|
31
49
|
|
32
50
|
delegate :find, :find_by_id, :where, :first, :first!, :last, :last!, :pluck, :order, :limit, :offset,
|
@@ -45,6 +63,10 @@ module FrozenRecord
|
|
45
63
|
|
46
64
|
private
|
47
65
|
|
66
|
+
def store
|
67
|
+
@store = ThreadSafeStorage.new(name)
|
68
|
+
end
|
69
|
+
|
48
70
|
def method_missing(name, *args)
|
49
71
|
if name.to_s =~ FIND_BY_PATTERN
|
50
72
|
return dynamic_match($1, args, $2.present?)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: frozen_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jean Boussier
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|