active_repository 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/active_repository/adapters/default_adapter.rb +5 -0
- data/lib/active_repository/adapters/persistence_adapter.rb +4 -0
- data/lib/active_repository/base.rb +2 -0
- data/lib/active_repository/version.rb +1 -1
- data/lib/active_repository/write_support.rb +19 -4
- data/lib/active_repository/writers.rb +10 -0
- data/spec/support/shared_examples.rb +16 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZDhkNGUzNGNjOTYzNzkwNWUzMTU4NzhkZmY0Yjc1NGZiOWZmYjlkNQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MWI4YjQ2ZjU0NTM5NTQ5ZjY3ZTM5MTMyZDhlYThmZDg3MmFhMDJkOA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NTU0NzhkNzU4ZjdhOTU0ODFkYmYwOTg4NzVjZDhlYjRmYWEwMmZjNjg5NGFl
|
10
|
+
YTE1ZTQyNTAzYTE0NTJiYTNlYjU2ZDRjNTI5ODNlYTQ5NTU1YmRjZDc2NTA4
|
11
|
+
MjA0ODg5MTMzYjkxNzU1MDZmNjRiNDI5ZDkyMjQ0ZTJiZTRjNWY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YjkzYjY4OGRmZjc0MjQzN2M2NmVjODE3YWQzNTk5NTdhZDhhMWM2ZGI3NDUy
|
14
|
+
MjQwYjZjZmRiMDc2ODYzOWNiMDlhYmVlNTYyMzUwZWMyYzAzYTlmYTkwZWJk
|
15
|
+
M2UyYjIxZGM0M2IzZTdjMDBmYTJmNWQxN2ExMzIxMTNmMzM5N2Q=
|
@@ -23,16 +23,23 @@ module ActiveHash
|
|
23
23
|
record_id = record.id.to_s
|
24
24
|
record_hash = record.hash
|
25
25
|
|
26
|
-
|
27
|
-
record_index.delete(record_id)
|
28
|
-
self.all.delete(record)
|
29
|
-
end
|
26
|
+
remove(record)
|
30
27
|
|
31
28
|
if record_index[record_id].nil? || !self.all.map(&:hash).include?(record_hash)
|
32
29
|
insert_record(record)
|
33
30
|
end
|
34
31
|
end
|
35
32
|
|
33
|
+
def self.remove(record)
|
34
|
+
record_id = record.id.to_s
|
35
|
+
record_hash = record.hash
|
36
|
+
|
37
|
+
if self.all.map(&:hash).include?(record_hash)
|
38
|
+
record_index.delete(record_id)
|
39
|
+
self.all.delete(record)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
36
43
|
def self.where(query)
|
37
44
|
if query.is_a?(String)
|
38
45
|
return ActiveHash::SQLQueryExecutor.execute(self, query)
|
@@ -69,6 +76,14 @@ module ActiveHash
|
|
69
76
|
end
|
70
77
|
end
|
71
78
|
|
79
|
+
def delete
|
80
|
+
record = self.class.find_by_id(self.id)
|
81
|
+
|
82
|
+
self.class.remove(self)
|
83
|
+
|
84
|
+
self.class.find_by_id(self.id).nil?
|
85
|
+
end
|
86
|
+
|
72
87
|
def to_param
|
73
88
|
id.present? ? id.to_s : nil
|
74
89
|
end
|
@@ -51,6 +51,16 @@ module ActiveRepository
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
+
# Deletes self from the repository.
|
55
|
+
def delete
|
56
|
+
klass = self.class
|
57
|
+
if klass.get_model_class == klass
|
58
|
+
super
|
59
|
+
else
|
60
|
+
PersistenceAdapter.delete(klass, self.id)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
54
64
|
# Updates #key attribute with #value value.
|
55
65
|
def update_attribute(key, value)
|
56
66
|
ret = self.valid?
|
@@ -631,6 +631,22 @@ shared_examples ".transaction" do
|
|
631
631
|
end
|
632
632
|
end
|
633
633
|
|
634
|
+
shared_examples "#delete" do
|
635
|
+
before do
|
636
|
+
Country.delete_all
|
637
|
+
end
|
638
|
+
|
639
|
+
it "removes a record" do
|
640
|
+
country = Country.create
|
641
|
+
|
642
|
+
Country.size.should == 1
|
643
|
+
|
644
|
+
country.delete
|
645
|
+
|
646
|
+
Country.size.should == 0
|
647
|
+
end
|
648
|
+
end
|
649
|
+
|
634
650
|
shared_examples ".delete_all" do
|
635
651
|
before do
|
636
652
|
Country.delete_all
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_repository
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Caio Torres
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_hash
|