mementus 0.1.3 → 0.1.4
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 +8 -8
- data/lib/mementus/relation.rb +14 -2
- data/lib/mementus/version.rb +1 -1
- data/spec/collection_spec.rb +5 -5
- data/spec/scopes_spec.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZjI1MGJjNDU2MzUzMTM4ZDliYTFhYWJiODdmOTdmOWIzOThhNTUzZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
N2UyODk0M2JkOGYzOThkNzY2NDM4OWIyNTAyOTI5ZDE3MTY5M2QyZQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
Y2VjZGFlYTUwM2EyOGU1OGY3ZjdhNjgwZGUyMTBlZGUwZDhjN2IwZjNiZTNl
|
10
|
+
Nzk2ZGRmODE0ZDZmODFkMjQyNjE5ZDA3ZjlhMzEyNmFkNzY3MjQ3YzAzMTg5
|
11
|
+
ZjJmYzVmNjViY2FhOGVkMmVhYTIzNzlhM2I4YmNjNGQxY2E4ZDI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NzMxZDhhOGY3MWY5NTFjMWM2ZjJjMTkxNjA0ZWM2ZDhlZjQyZjUxNmE3NjYx
|
14
|
+
MTA2ZDUxMzYwNWQ0MWU4NjcxN2Y4ODY0MGQyNjdiNjRhYmNmM2Q0YjRhMzY0
|
15
|
+
Nzg1MmZmMjBjM2E3ZDAyOTIxM2ZmZTZmMDM5M2RjM2ZkNmI2MGM=
|
data/lib/mementus/relation.rb
CHANGED
@@ -7,7 +7,7 @@ module Mementus
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def all
|
10
|
-
Query.new(self.collection, self.cache).
|
10
|
+
Query.new(self.collection, self.cache).objects
|
11
11
|
end
|
12
12
|
|
13
13
|
def order(constraints)
|
@@ -45,12 +45,24 @@ module Mementus
|
|
45
45
|
end
|
46
46
|
|
47
47
|
# Materializes the relation to an array of model objects.
|
48
|
-
def
|
48
|
+
def objects
|
49
49
|
@relation.inject([]) do |list, relation|
|
50
50
|
list << @cache[relation[:__cache_key]]
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
+
# Enumerate over each object.
|
55
|
+
def each(&block)
|
56
|
+
@relation.each do |relation|
|
57
|
+
yield block
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# Number of objects.
|
62
|
+
def count
|
63
|
+
objects.count
|
64
|
+
end
|
65
|
+
|
54
66
|
end
|
55
67
|
end
|
56
68
|
end
|
data/lib/mementus/version.rb
CHANGED
data/spec/collection_spec.rb
CHANGED
@@ -28,16 +28,16 @@ describe Mementus::Model do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
it "finds item by equality match" do
|
31
|
-
collection = Item.where(order: 10)
|
31
|
+
collection = Item.where(order: 10)
|
32
32
|
expect(collection.count).to eq 1
|
33
|
-
expect(collection.first.name).to eq "Item: 9"
|
33
|
+
expect(collection.objects.first.name).to eq "Item: 9"
|
34
34
|
end
|
35
35
|
|
36
36
|
it "finds items by predicate match" do
|
37
|
-
collection = Item.order(order: :desc)
|
37
|
+
collection = Item.order(order: :desc)
|
38
38
|
expect(collection.count).to eq 20
|
39
|
-
expect(collection.first.name).to eq "Item: 19"
|
40
|
-
expect(collection.last.name).to eq "Item: 0"
|
39
|
+
expect(collection.objects.first.name).to eq "Item: 19"
|
40
|
+
expect(collection.objects.last.name).to eq "Item: 0"
|
41
41
|
end
|
42
42
|
|
43
43
|
end
|
data/spec/scopes_spec.rb
CHANGED
@@ -21,8 +21,8 @@ describe Mementus::Model do
|
|
21
21
|
describe "#scope" do
|
22
22
|
|
23
23
|
it "can execute named scopes" do
|
24
|
-
expect(CuteThing.cats.
|
25
|
-
expect(CuteThing.dogs.
|
24
|
+
expect(CuteThing.cats.count).to eq 10
|
25
|
+
expect(CuteThing.dogs.count).to eq 10
|
26
26
|
end
|
27
27
|
|
28
28
|
end
|