Sha256: 24ebf31d6d23b04112e32188bede21982447fa480f3321d26b130a7f05e953b9

Contents?: true

Size: 867 Bytes

Versions: 8

Compression:

Stored size: 867 Bytes

Contents

module Representable
  class Binding
    attr_reader :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

8 entries across 8 versions & 1 rubygems

Version Path
representable-1.1.7 lib/representable/binding.rb
representable-1.1.6 lib/representable/binding.rb
representable-1.1.5 lib/representable/binding.rb
representable-1.1.4 lib/representable/binding.rb
representable-1.1.3 lib/representable/binding.rb
representable-1.1.2 lib/representable/binding.rb
representable-1.1.1 lib/representable/binding.rb
representable-1.1.0 lib/representable/binding.rb