<commit_before>require 'base64'
require 'mkxms/mssql/utils'

module Mkxms; end

module Mkxms::Mssql
  module ExtendedProperties
    def extended_properties
      @extended_properties ||= {}
    end
  end
  
  module Property
    def self.addition_sql(name, value, subject_identification_parts)
      "EXEC sp_addextendedproperty N'%s', %s, %s;" % [
        name,
        value,
        subject_identification_parts.map {|part| "N'#{part}'"}.join(', ')
      ]
    end
    
    module Hosting
      def extended_properties_sql
        self.extended_properties.each_pair.map do |name, value|
          Mkxms::Mssql::Property.addition_sql(name, value, self.property_subject_identifiers)
        end.tap do |v|
          class <<v
            def joined_on_new_lines(indent: '    ')
              map {|i| "\n" + indent + i}.join('')
            end
          end
        end
      end
    end
    
    module SchemaScoped
      def property_subject_identifiers
        ['SCHEMA', Utils::unquoted_name(schema), self.class::SQL_OBJECT_TYPE.upcase, Utils.unquoted_name(name)]
      end
      
      def subitem_extended_properties_sql(subitem)
        subitem.extended_properties.each_pair.map do |name, value|
          Mkxms::Mssql::Property.addition_sql(
            name, value,
            property_subject_identifiers + [subitem.class::SQL_OBJECT_TYPE.upcase, Utils.unquoted_name(subitem.name)]
          )
        end
      end
    end
  end

  class PropertyHandler
    module ElementHandler
      def handle_property_element(parse)
        parse.context = PropertyHandler.new(self, parse.node.attributes)
      end
    end
    
    def initialize(describable, attrs)
      @describable = describable<commit_msg>Simplify property parsing<commit_after>require 'base64'
require 'mkxms/mssql/utils'

module Mkxms; end

module Mkxms::Mssql
  module ExtendedProperties
    def extended_properties
      @extended_properties ||= {}
    end
  end
  
  module Property
    def self.addition_sql(name, value, subject_identification_parts)
      "EXEC sp_addextendedproperty N'%s', %s, %s;" % [
        name,
        value,
        subject_identification_parts.map {|part| "N'#{part}'"}.join(', ')
      ]
    end
    
    module Hosting
      def extended_properties_sql
        self.extended_properties.each_pair.map do |name, value|
          Mkxms::Mssql::Property.addition_sql(name, value, self.property_subject_identifiers)
        end.tap do |v|
          class <<v
            def joined_on_new_lines(indent: '    ')
              map {|i| "\n" + indent + i}.join('')
            end
          end
        end
      end
    end
    
    module SchemaScoped
      def property_subject_identifiers
        ['SCHEMA', Utils::unquoted_name(schema), self.class::SQL_OBJECT_TYPE.upcase, Utils.unquoted_name(name)]
      end
      
      def subitem_extended_properties_sql(subitem)
        subitem.extended_properties.each_pair.map do |name, value|
          Mkxms::Mssql::Property.addition_sql(
            name, value,
            property_subject_identifiers + [subitem.class::SQL_OBJECT_TYPE.upcase, Utils.unquoted_name(subitem.name)]
          )
        end
      end
    end
  end

  class PropertyHandler
    module ElementHandler
      def handle_property_element(parse)
        parse.context = PropertyHandler.new(self, parse.node.attributes)
      end
      
      private
      def store_properties_on(target)
        define_singleton_method(:extended_properties) do
          target.extended_properties
        end
        return target
      end
    end
    
    def initialize(describable, attrs)
      @describable = describable
{'fraction_non_alphanumeric': 0.08853450646136926, 'fraction_numerical': 0.0010998075336816058, 'mean_word_length': 2.4418164616840112, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '6020332', 'n_tokens_mistral': 1141, 'n_tokens_neox': 1115, 'n_words': 215}