rrepo 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rrepo/repository.rb +20 -8
- data/lib/rrepo/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: 7f7d90ccdf68a5f7982f1f0e456481185c328f97
|
4
|
+
data.tar.gz: 074a1fb8b2112f4df91efe51d2d0caa99ebe5b81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8421ce9ef55652c69e4aa3352c4960a2af5a6ffe0d595381a5c79f2446b8d3001da72428bd823e22aa47004340b2adc5348c74375edccdbcd2ac9d0056118de9
|
7
|
+
data.tar.gz: 9b561e91101fdd12c9bce674c955112e02cd862c67f00cb5802601bfa6737ebea5db68a2670ac3ecf1c15afcec005501b2b17f94ee56c393cda085e2b40e5151
|
data/lib/rrepo/repository.rb
CHANGED
@@ -14,22 +14,19 @@ module RRepo
|
|
14
14
|
@collection
|
15
15
|
end
|
16
16
|
|
17
|
-
def model_class_name(name = nil)
|
17
|
+
def model_class_name(name = nil, &block)
|
18
18
|
return @model_class_name = name if name.present?
|
19
|
+
return @model_class_name = block if block_given?
|
19
20
|
@model_class_name
|
20
21
|
end
|
21
22
|
end
|
22
23
|
|
23
|
-
attr_reader :collection, :adapter
|
24
|
+
attr_reader :collection, :adapter
|
24
25
|
|
25
26
|
def initialize(adapter)
|
26
27
|
@adapter = adapter
|
27
28
|
class_name = self.class.name.demodulize
|
28
29
|
@collection = (self.class.collection || class_name.underscore).to_sym
|
29
|
-
return if class_name == 'Repository'
|
30
|
-
@model_class = (
|
31
|
-
self.class.model_class_name || class_name.singularize
|
32
|
-
).constantize
|
33
30
|
end
|
34
31
|
|
35
32
|
def create(model)
|
@@ -55,12 +52,12 @@ module RRepo
|
|
55
52
|
|
56
53
|
def all
|
57
54
|
result = adapter.all(collection)
|
58
|
-
result.map(&
|
55
|
+
result.map(&method(:model_for))
|
59
56
|
end
|
60
57
|
|
61
58
|
def find(id)
|
62
59
|
result = adapter.find(collection, id)
|
63
|
-
|
60
|
+
model_for(result)
|
64
61
|
end
|
65
62
|
|
66
63
|
def clear
|
@@ -70,5 +67,20 @@ module RRepo
|
|
70
67
|
def query(&block)
|
71
68
|
adapter.query(collection, &block)
|
72
69
|
end
|
70
|
+
|
71
|
+
def model_class(attributes = {})
|
72
|
+
if self.class.model_class_name.respond_to?(:call)
|
73
|
+
model_class_name = self.class.model_class_name.call(attributes)
|
74
|
+
else
|
75
|
+
model_class_name = (
|
76
|
+
self.class.model_class_name || self.class.name.demodulize.singularize
|
77
|
+
)
|
78
|
+
end
|
79
|
+
model_class_name.constantize
|
80
|
+
end
|
81
|
+
|
82
|
+
def model_for(attributes)
|
83
|
+
model_class(attributes).new(attributes)
|
84
|
+
end
|
73
85
|
end
|
74
86
|
end
|
data/lib/rrepo/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rrepo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joakim Reinert
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|