lib/representable.rb in representable-1.2.9 vs lib/representable.rb in representable-1.3.0

- old
+ new

@@ -40,20 +40,20 @@ end end # Reads values from +doc+ and sets properties accordingly. def update_properties_from(doc, options, format) - representable_bindings_for(format).each do |bin| + representable_bindings_for(format, options).each do |bin| deserialize_property(bin, doc, options) end self end private # Compiles the document going through all properties. def create_representation_with(doc, options, format) - representable_bindings_for(format).each do |bin| + representable_bindings_for(format, options).each do |bin| serialize_property(bin, doc, options) end doc end @@ -86,46 +86,37 @@ end # Retrieve value and write fragment to the doc. def compile_fragment(bin, doc) value = send(bin.getter) - value = bin.default_for(value) - write_fragment_for(bin, value, doc) + bin.write_fragment(doc, value) end # Parse value from doc and update the model property. def uncompile_fragment(bin, doc) - value = read_fragment_for(bin, doc) - - if value == Binding::FragmentNotFound - return unless bin.has_default? - value = bin.default + bin.read_fragment(doc) do |value| + send(bin.setter, value) end - - send(bin.setter, value) end - def write_fragment_for(bin, value, doc) # DISCUSS: move to Binding? - return if bin.skipable_nil_value?(value) - bin.write(doc, value) - end - - def read_fragment_for(bin, doc) # DISCUSS: move to Binding? - bin.read(doc) - end - def representable_attrs @representable_attrs ||= self.class.representable_attrs # DISCUSS: copy, or better not? end - def representable_bindings_for(format) - representable_attrs.map {|attr| format.build_for(attr, self) } + def representable_bindings_for(format, options) + options = cleanup_options(options) # FIXME: make representable-options and user-options two different hashes. + representable_attrs.map {|attr| format.build_for(attr, self, options) } end # Returns the wrapper for the representation. Mostly used in XML. def representation_wrap representable_attrs.wrap_for(self.class.name) + end + +private + def cleanup_options(options) # TODO: remove me. + options.reject { |k,v| [:include, :exclude].include?(k) } end module ClassInclusions def included(base) super