platanus 0.0.23 → 0.0.24
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.
- data/lib/platanus/serializers/json_sym.rb +16 -0
- data/lib/platanus/stacked.rb +4 -4
- data/lib/platanus/version.rb +1 -1
- data/lib/platanus.rb +2 -0
- metadata +3 -2
@@ -0,0 +1,16 @@
|
|
1
|
+
# json_sym.rb : Symbolized keys json serializer.
|
2
|
+
#
|
3
|
+
# Copyright October 2012, Ignacio Baixas +mailto:ignacio@platan.us+.
|
4
|
+
|
5
|
+
class JSONSym
|
6
|
+
|
7
|
+
def self.load(_str)
|
8
|
+
return nil if _str.nil?
|
9
|
+
MultiJson.load(_str, symbolize_keys: true)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.dump(_data)
|
13
|
+
MultiJson.dump(_data)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
data/lib/platanus/stacked.rb
CHANGED
@@ -78,14 +78,14 @@ module Platanus
|
|
78
78
|
# setup main association
|
79
79
|
has_many _name, _options
|
80
80
|
|
81
|
-
cache_step = ->(_ctx, _top) {
|
81
|
+
cache_step = ->(_ctx, _top, _top_is_new) {
|
82
82
|
# cache required fields
|
83
83
|
return if to_cache.nil?
|
84
84
|
to_cache.each do |cache_attr|
|
85
85
|
value = if cache_attr.has_key? :from
|
86
86
|
_top.nil? ? _top : _top.send(cache_attr[:from])
|
87
87
|
else
|
88
|
-
_ctx.send(cache_attr[:virtual], _top)
|
88
|
+
_ctx.send(cache_attr[:virtual], _top, _top_is_new)
|
89
89
|
end
|
90
90
|
_ctx.send(cache_attr[:to].to_s + '=', value)
|
91
91
|
end
|
@@ -103,7 +103,7 @@ module Platanus
|
|
103
103
|
self.class.transaction do
|
104
104
|
|
105
105
|
# cache, then save if new, then push and finally process state
|
106
|
-
cache_step.call(self, obj)
|
106
|
+
cache_step.call(self, obj, true)
|
107
107
|
self.save! if self.new_record? # make sure there is an id BEFORE pushing
|
108
108
|
raise ActiveRecord::RecordInvalid.new(obj) unless send(tname).send('<<',obj)
|
109
109
|
after_step.call(self, obj)
|
@@ -125,7 +125,7 @@ module Platanus
|
|
125
125
|
|
126
126
|
# find current top, then restore stack state
|
127
127
|
top = self.send(_name).first
|
128
|
-
cache_step.call(self, top)
|
128
|
+
cache_step.call(self, top, false)
|
129
129
|
after_step.call(self, top)
|
130
130
|
|
131
131
|
self.save! if self.changed?
|
data/lib/platanus/version.rb
CHANGED
data/lib/platanus.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: platanus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.24
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-23 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Platan.us utility gem
|
15
15
|
email:
|
@@ -33,6 +33,7 @@ files:
|
|
33
33
|
- lib/platanus/http_helpers.rb
|
34
34
|
- lib/platanus/layered.rb
|
35
35
|
- lib/platanus/onetime.rb
|
36
|
+
- lib/platanus/serializers/json_sym.rb
|
36
37
|
- lib/platanus/stacked.rb
|
37
38
|
- lib/platanus/templates/prawn.rb
|
38
39
|
- lib/platanus/templates/spreadsheet.rb
|