<commit_before>module Roar
  # deserialize
  # serialize
  module Representer
    class Base
      class_attribute :represented_class
      class_attribute :mime_type
      
      class << self
        def represents(klass, options) # DISCUSS: what if we don't want to hard-wire these settings into the representer?
          self.represented_class = klass
          self.mime_type = options[:as]
        end
        
      private
        def from_xml(*)
        end
      end
      
      # DISCUSS: serialize on instance?
      def serialize(represented, mime_type)
        
      end
      
      #def serialize_model(model)
      #  serialize(model.attributes)
      #end
      
      
    private
      def to_xml(*) # call #serialize instead.
      end
      
    end
    
    require "roxml/definition"
    class LinksDefinition < ROXML::Definition
      def rel2block
        @rel2block ||= []
      end
      
      def populate(representer, *args)
        representer.links ||= []
        
        rel2block.each do |link|
          representer.links << Roar::Representer::Roxml::Hyperlink.from_attributes({
            "rel"   => link[:rel],
            "href"  => representer.instance_exec(&link[:block])})  # DISCUSS: run block in representer context?
        end
      end
    end
    
  end
end<commit_msg>use sought_type and stay dry.<commit_after>module Roar
  # deserialize
  # serialize
  module Representer
    class Base
      class_attribute :represented_class
      class_attribute :mime_type
      
      class << self
        def represents(klass, options) # DISCUSS: what if we don't want to hard-wire these settings into the representer?
          self.represented_class = klass
          self.mime_type = options[:as]
        end
        
      private
        def from_xml(*)
        end
      end
      
      # DISCUSS: serialize on instance?
      def serialize(represented, mime_type)
        
      end
      
      #def serialize_model(model)
      #  serialize(model.attributes)
      #end
      
      
    private
      def to_xml(*) # call #serialize instead.
      end
      
    end
    
    require "roxml/definition"
    class LinksDefinition < ROXML::Definition
      def rel2block
        @rel2block ||= []
      end
      
      def populate(representer, *args)
        representer.links ||= []
        
        rel2block.each do |link|
          representer.links << sought_type.from_attributes({  # create Hyperlink representer.
            "rel"   => link[:rel],
            "href"  => representer.instance_exec(&link[:block])})  # DISCUSS: run block in representer context?
        end
      end
    end
    
  end
end
{'fraction_non_alphanumeric': 0.07980517047583364, 'fraction_numerical': 0.0022480329711502436, 'mean_word_length': 1.8404255319148937, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 7}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4191444', 'n_tokens_mistral': 783, 'n_tokens_neox': 753, 'n_words': 192}