module Representable::Mapper::Methods
Public Class Methods
new(bindings)
click to toggle source
# File lib/representable/mapper.rb, line 6 def initialize(bindings) @bindings = bindings end
Public Instance Methods
bindings(represented, options)
click to toggle source
# File lib/representable/mapper.rb, line 10 def bindings(represented, options) @bindings.each do |binding| binding.update!(represented, options) end end
deserialize(represented, doc, options, private_options)
click to toggle source
# File lib/representable/mapper.rb, line 16 def deserialize(represented, doc, options, private_options) bindings(represented, options).each do |bin| deserialize_property(bin, doc, options, private_options) end represented end
serialize(represented, doc, options, private_options)
click to toggle source
# File lib/representable/mapper.rb, line 23 def serialize(represented, doc, options, private_options) bindings(represented, options).each do |bin| serialize_property(bin, doc, options, private_options) end doc end
Private Instance Methods
compile_fragment(bin, doc)
click to toggle source
# File lib/representable/mapper.rb, line 72 def compile_fragment(bin, doc) bin.compile_fragment(doc) end
deserialize_property(binding, doc, options, private_options)
click to toggle source
# File lib/representable/mapper.rb, line 36 def deserialize_property(binding, doc, options, private_options) return if skip_property?(binding, private_options.merge(:action => :deserialize)) uncompile_fragment(binding, doc) end
serialize_property(binding, doc, options, private_options)
click to toggle source
# File lib/representable/mapper.rb, line 31 def serialize_property(binding, doc, options, private_options) return if skip_property?(binding, private_options.merge(:action => :serialize)) compile_fragment(binding, doc) end
skip_conditional_property?(binding)
click to toggle source
# File lib/representable/mapper.rb, line 61 def skip_conditional_property?(binding) return unless condition = binding[:if] not binding.evaluate_option(:if) end
skip_excluded_property?(binding, private_options)
click to toggle source
# File lib/representable/mapper.rb, line 55 def skip_excluded_property?(binding, private_options) return unless props = private_options[:exclude] || private_options[:include] res = props.include?(binding.name.to_sym) private_options[:include] ? !res : res end
skip_property?(binding, private_options)
click to toggle source
Checks and returns if the property should be included.
1.78 0.107 0.025 0.000 0.081 30002 Representable::Mapper::Methods#skip_property? 0.96 0.013 0.013 0.000 0.000 30002 Representable::Mapper::Methods#skip_property? hash only 1.15 0.025 0.016 0.000 0.009 30002 Representable::Mapper::Methods#skip_property?
# File lib/representable/mapper.rb, line 46 def skip_property?(binding, private_options) return unless private_options[:include] || private_options[:exclude] || binding.skip_filters? return true if skip_excluded_property?(binding, private_options) # no need for further evaluation when :exclude'ed return true if skip_protected_property(binding, private_options) skip_conditional_property?(binding) end
skip_protected_property(binding, private_options)
click to toggle source
DISCUSS: this could be just another :if option in a Pipeline?
# File lib/representable/mapper.rb, line 68 def skip_protected_property(binding, private_options) private_options[:action] == :serialize ? binding[:readable] == false : binding[:writeable] == false end
uncompile_fragment(bin, doc)
click to toggle source
# File lib/representable/mapper.rb, line 76 def uncompile_fragment(bin, doc) bin.uncompile_fragment(doc) end