Sha256: acd1942d33387c3f83d5c51a506035341c89e4f57ce6aeb953cba06d8297495b

Contents?: true

Size: 952 Bytes

Versions: 3

Compression:

Stored size: 952 Bytes

Contents

module Representable
  class Binding
    class FragmentNotFound
    end
    
    
    attr_reader :definition # TODO: merge Binding and Definition.
  
    def initialize(definition)
      @definition = definition
    end
    
    # Main entry point for rendering/parsing a property object.
    module Hooks
      def serialize(value)
        value
      end
      
      def deserialize(fragment)
        fragment
      end
    end
    
    include Hooks
    
    
    # Hooks into #serialize and #deserialize to extend typed properties
    # at runtime.
    module Extend
      # Extends the object with its representer before serialization.
      def serialize(object)
        extend_for(super)
      end
      
      def deserialize(*)
        extend_for(super)
      end
      
      def extend_for(object)
        if mod = definition.representer_module
          object.extend(*mod)
        end
        
        object
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
representable-1.2.3 lib/representable/binding.rb
representable-1.2.2 lib/representable/binding.rb
representable-1.2.1 lib/representable/binding.rb