module Subledger::Domain::Roles::Restable
Public Instance Methods
patch_hash()
click to toggle source
# File lib/subledger/domain/roles/restable.rb, line 17 def patch_hash hash = { } self.class.patch_keys.each do |key| value = self.send key hash[key] = translate( key, value ) unless exclude? value end hash end
post_hash()
click to toggle source
# File lib/subledger/domain/roles/restable.rb, line 5 def post_hash hash = { } self.class.post_keys.each do |key| value = self.send key hash[key] = translate( key, value ) unless exclude? value end hash end
serializable_hash()
click to toggle source
# File lib/subledger/domain/roles/restable.rb, line 29 def serializable_hash entity = self.class::Entity.new self hash = entity.serializable_hash hash.each do |key, value| hash.delete( key ) if exclude? value end hash end
to_json()
click to toggle source
# File lib/subledger/domain/roles/restable.rb, line 41 def to_json MultiJson.dump serializable_hash end
Private Instance Methods
exclude?(value)
click to toggle source
# File lib/subledger/domain/roles/restable.rb, line 63 def exclude? value value.nil? or ( value.kind_of?( String ) and value.length.zero? ) end
translate(key, value)
click to toggle source
TODO elimate this using serializable hash
# File lib/subledger/domain/roles/restable.rb, line 48 def translate key, value case key.to_s when /at$/ value.iso8601(3) when 'org', 'book', 'account', 'journal_entry', 'identity', 'report' value.id when 'value' value.rest_hash when 'normal_balance' value.type else value end end