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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MjM0MTczODAxNTlkNmQ3ODYwMzdlYWEzNzNjMGIyNTE1YWQ2NWZiMw==
4
+ ZjI1MGJjNDU2MzUzMTM4ZDliYTFhYWJiODdmOTdmOWIzOThhNTUzZA==
5
5
  data.tar.gz: !binary |-
6
- YTgyZDJmZjFlMTY0NjUwODNkMDI0OWZjYTIzYzBjYjZhOTUzMTc0Yw==
6
+ N2UyODk0M2JkOGYzOThkNzY2NDM4OWIyNTAyOTI5ZDE3MTY5M2QyZQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YjEwYWFhNmIwYWFhYjM3NWNmNDg2ZjY4MTMxZWI5ZDc0M2ZjOTk1ZDFkY2Mw
10
- YzA0YTYzOTIyYTI4ODViY2U0ZDRhNTA4NDQ2YzIwOTA3ZTYxOWFjYmNhNmEz
11
- OTcwYjFiODNhYjhmMjI5YTRlNDJlZDc4NjA3ODIwZGUyMWI3YWM=
9
+ Y2VjZGFlYTUwM2EyOGU1OGY3ZjdhNjgwZGUyMTBlZGUwZDhjN2IwZjNiZTNl
10
+ Nzk2ZGRmODE0ZDZmODFkMjQyNjE5ZDA3ZjlhMzEyNmFkNzY3MjQ3YzAzMTg5
11
+ ZjJmYzVmNjViY2FhOGVkMmVhYTIzNzlhM2I4YmNjNGQxY2E4ZDI=
12
12
  data.tar.gz: !binary |-
13
- MGM2ODcxNzYxMmViMjI1YjM5NjMyZmNjZDNiNDVhOWJhMjg4N2FmMjk4YTMz
14
- ZjY4Y2QyNzgwZGFlODJlZjk5NTA5MjQyZTMzZTIxODFjMTdmZmIwZWM4MDFm
15
- NTdlZDEzYTg5ZWU1M2RiZjAzZDQxMmRlOTY3M2RlOWJhYzUyNzg=
13
+ NzMxZDhhOGY3MWY5NTFjMWM2ZjJjMTkxNjA0ZWM2ZDhlZjQyZjUxNmE3NjYx
14
+ MTA2ZDUxMzYwNWQ0MWU4NjcxN2Y4ODY0MGQyNjdiNjRhYmNmM2Q0YjRhMzY0
15
+ Nzg1MmZmMjBjM2E3ZDAyOTIxM2ZmZTZmMDM5M2RjM2ZkNmI2MGM=
@@ -7,7 +7,7 @@ module Mementus
7
7
  end
8
8
 
9
9
  def all
10
- Query.new(self.collection, self.cache).all
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 all
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
@@ -1,3 +1,3 @@
1
1
  module Mementus
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -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).all
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).all
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.all.count).to eq 10
25
- expect(CuteThing.dogs.all.count).to eq 10
24
+ expect(CuteThing.cats.count).to eq 10
25
+ expect(CuteThing.dogs.count).to eq 10
26
26
  end
27
27
 
28
28
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mementus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - maetl