platanus 0.0.23 → 0.0.24

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -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?
@@ -1,3 +1,3 @@
1
1
  module Platanus
2
- VERSION = "0.0.23" # 0.1 will come with tests!
2
+ VERSION = "0.0.24" # 0.1 will come with tests!
3
3
  end
data/lib/platanus.rb CHANGED
@@ -13,6 +13,8 @@ require 'platanus/http_helpers'
13
13
  # require 'platanus/template/spreadsheet'
14
14
  # require 'platanus/template/prawn'
15
15
 
16
+ require 'platanus/serializers/json_sym'
17
+
16
18
  module Platanus
17
19
  # Your code goes here...
18
20
  end
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.23
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 00:00:00.000000000 Z
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