garland 0.11 → 0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/garland_rails.rb +39 -5
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 633f8442d2f0646ca3e812f01370fd4ebbcc3f93
|
4
|
+
data.tar.gz: 78d637e6b0ea8a790a7cb8ec446acb861938a625
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 321978763b6b8bed65d58cab3b24c855234cc85f2991107f8bd82fe2cf121e0f669c042fa51d061c11719e26d0a242b5eff2214362821151b5cd3884c28b883c
|
7
|
+
data.tar.gz: 5981c569dab5ab5467ce1593e22758b166706541804ca3da3d6623326efead50651d612655ab8eafdd55cc8916f136200ac7371789ba7eac658fc16fb888de35
|
data/lib/garland_rails.rb
CHANGED
@@ -2,6 +2,28 @@ module GarlandRails
|
|
2
2
|
DIFF = true
|
3
3
|
SNAPSHOT = false
|
4
4
|
|
5
|
+
module Extend
|
6
|
+
def self.included(base)
|
7
|
+
base.extend(self)
|
8
|
+
end
|
9
|
+
|
10
|
+
def has_many(name, scope = nil, options = {}, &extension)
|
11
|
+
name_superclass = name.to_s.classify.constantize.superclass
|
12
|
+
if name_superclass == GarlandRails::Base
|
13
|
+
# if there are no scope and there are some options,
|
14
|
+
# scope will contain options, and we need to swap them
|
15
|
+
if scope.class == Hash
|
16
|
+
options = scope
|
17
|
+
scope = nil
|
18
|
+
end
|
19
|
+
|
20
|
+
options = options.merge({ as: :belongs_to })
|
21
|
+
end
|
22
|
+
|
23
|
+
super(name, scope, options, &extension)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
5
27
|
class Base < Garland
|
6
28
|
self.table_name = "garlands"
|
7
29
|
|
@@ -16,10 +38,16 @@ module GarlandRails
|
|
16
38
|
:next,
|
17
39
|
], conditions: -> { where("next IS NULL OR previous IS NULL") }
|
18
40
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
41
|
+
# everything seems to work without `polymorphic: true`,
|
42
|
+
# but we will set it just for accordance to docs
|
43
|
+
def self.belongs_to(name, scope = nil, options = {}, &extension)
|
44
|
+
if scope.class == Hash
|
45
|
+
options = scope
|
46
|
+
scope = nil
|
47
|
+
end
|
48
|
+
options = options.merge({ polymorphic: true })
|
49
|
+
|
50
|
+
super(name, scope, options, &extension)
|
23
51
|
end
|
24
52
|
|
25
53
|
def self.push(args)
|
@@ -106,13 +134,14 @@ module GarlandRails
|
|
106
134
|
# third+: diffs
|
107
135
|
unless brand_new_tail.save
|
108
136
|
Rails.logger.error("Unable to create new tail with props '#{tail_props}'")
|
137
|
+
ActiveRecord::Base.connection.release_savepoint("savepoint_before_init")
|
109
138
|
return nil
|
110
139
|
end
|
111
140
|
|
112
141
|
# belongs_to validations were in `brand_new_tail.save`
|
113
142
|
# here and below validations may be skipped as long as we check for continuity later
|
114
|
-
first_diff.save(validate: false)
|
115
143
|
brand_new_head.save(validate: false)
|
144
|
+
first_diff.save(validate: false)
|
116
145
|
brand_new_tail.update_attribute(:next, first_diff.id)
|
117
146
|
first_diff.update_attribute(:previous, brand_new_tail.id)
|
118
147
|
first_diff.update_attribute(:next, brand_new_head.id)
|
@@ -121,6 +150,7 @@ module GarlandRails
|
|
121
150
|
unless self.continuous?(belongs_to)
|
122
151
|
Rails.logger.error("Initialized garland is not continuous")
|
123
152
|
ActiveRecord::Base.connection.exec_rollback_to_savepoint("savepoint_before_init")
|
153
|
+
ActiveRecord::Base.connection.release_savepoint("savepoint_before_init")
|
124
154
|
return nil
|
125
155
|
end
|
126
156
|
end
|
@@ -151,6 +181,7 @@ module GarlandRails
|
|
151
181
|
# because we don't want to check for continuity on every push
|
152
182
|
unless new_diff.save
|
153
183
|
Rails.logger.error("Unable to create new_diff with props '#{new_diff_props}'")
|
184
|
+
ActiveRecord::Base.connection.release_savepoint("savepoint_before_init")
|
154
185
|
return nil
|
155
186
|
end
|
156
187
|
|
@@ -158,6 +189,7 @@ module GarlandRails
|
|
158
189
|
unless last_diff.save
|
159
190
|
Rails.logger.error("Unable to save last_diff with 'next' = '#{new_diff.id}'")
|
160
191
|
ActiveRecord::Base.connection.exec_rollback_to_savepoint("savepoint_before_insert_diff")
|
192
|
+
ActiveRecord::Base.connection.release_savepoint("savepoint_before_init")
|
161
193
|
return nil
|
162
194
|
end
|
163
195
|
|
@@ -165,6 +197,7 @@ module GarlandRails
|
|
165
197
|
unless head.save
|
166
198
|
Rails.logger.error("Unable to save head with 'previous' = '#{new_diff.id}'")
|
167
199
|
ActiveRecord::Base.connection.exec_rollback_to_savepoint("savepoint_before_insert_diff")
|
200
|
+
ActiveRecord::Base.connection.release_savepoint("savepoint_before_init")
|
168
201
|
return nil
|
169
202
|
end
|
170
203
|
|
@@ -172,6 +205,7 @@ module GarlandRails
|
|
172
205
|
unless head.save
|
173
206
|
Rails.logger.error("Unable to save head with 'entity' = '#{hash.to_s}'")
|
174
207
|
ActiveRecord::Base.connection.exec_rollback_to_savepoint("savepoint_before_insert_diff")
|
208
|
+
ActiveRecord::Base.connection.release_savepoint("savepoint_before_init")
|
175
209
|
return nil
|
176
210
|
end
|
177
211
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: garland
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.12'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Morozov
|
@@ -24,8 +24,8 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
description: Provides GarlandRails::Base class for ActiveRecord, which allows
|
28
|
-
Hashes using snapshots and diffs.
|
27
|
+
description: Provides GarlandRails::Base class for ActiveRecord, which allows you
|
28
|
+
to save Hashes using snapshots and diffs (in short, it's HashDiff Rails storage).
|
29
29
|
email: ntcomp12@gmail.com
|
30
30
|
executables: []
|
31
31
|
extensions: []
|