garland 1.0.1 → 1.2.0

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/garland_rails.rb +19 -5
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 94143b495a7b352952ac1ba4dceef535a628a730
4
- data.tar.gz: ca1755f63483693ecb8945532c05b5d148b6108b
3
+ metadata.gz: a2b288498ddb5433e1531d660e8a016131d85965
4
+ data.tar.gz: 5f90325f1edf6ebb8c90e7c7c227fb60dc222f23
5
5
  SHA512:
6
- metadata.gz: 0aa5890da156ed025662a8df87464d1f6aca63cd01399f401560d977ec97b1b2919547132a255e204ced0e340bbfd83240bbd6e0997c54663da1f64655a5221a
7
- data.tar.gz: d5b549ed770a7e9283289590c0ab171b114a9ccd7735d93735a0b8dbaa4ad3adbd024eeee925532f399f213bbcb7705b1f09ac7b0d76d8bb3aca5748a10197b3
6
+ metadata.gz: 8771347f6b30260954a864529e7b9943e74c4d7ba23c5d116bb953b043290d075c69f6c669337f4dcc9744b223d22b1c71e0558a5c7d52df4ec44071acffaab7
7
+ data.tar.gz: 8e849c82f4e935bbfb1e751f2f9e7401134b41d18c729b3907c7d46a2baf05b37fa7158472851a4e80951a5cf837fad10ceabca76073f6dca71b7588ccea6e20
@@ -107,6 +107,20 @@ module GarlandRails
107
107
  self.find_by(id: head.previous_id)
108
108
  end
109
109
 
110
+ def next
111
+ Garland.find(self.next_id)
112
+ end
113
+
114
+ def previous
115
+ Garland.find(self.previous_id)
116
+ end
117
+
118
+ def safe_eval_entity
119
+ return nil unless self.entity =~ /\[.*\]/ || self.entity =~ /{.*}/
120
+
121
+ eval(self.entity)
122
+ end
123
+
110
124
  def self.table_type(record)
111
125
  record.class.name
112
126
  end
@@ -165,7 +179,7 @@ module GarlandRails
165
179
  last_diff = self.find_by(id: head.previous_id)
166
180
  common_props = self._split_belongs_to(belongs_to)
167
181
 
168
- diff = HashDiffSym.diff(eval(head.entity), hash)
182
+ diff = HashDiffSym.diff(head.safe_eval_entity, hash)
169
183
  return unless diff.any?
170
184
 
171
185
  new_diff_props = common_props.merge(
@@ -221,19 +235,19 @@ module GarlandRails
221
235
  return false unless tail && head
222
236
 
223
237
  current_bulb = tail
224
- current_hash = eval(tail.entity)
238
+ current_hash = tail.safe_eval_entity
225
239
  items_counted = 1
226
240
  while current_bulb.next_id do
227
241
  items_counted += 1
228
- current_bulb = self.find_by(id: current_bulb.next_id)
242
+ current_bulb = current_bulb.next
229
243
  if current_bulb.entity_type == DIFF
230
- current_hash = HashDiffSym.patch!(current_hash, eval(current_bulb.entity))
244
+ current_hash = HashDiffSym.patch!(current_hash, current_bulb.safe_eval_entity)
231
245
  else
232
246
  break
233
247
  end
234
248
  end
235
249
 
236
- items_counted == self.thread(belongs_to).size && current_hash == eval(head.entity)
250
+ items_counted == self.thread(belongs_to).size && current_hash == head.safe_eval_entity
237
251
  end
238
252
 
239
253
  private
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: garland
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Morozov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-20 00:00:00.000000000 Z
11
+ date: 2017-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashdiff_sym