<commit_before>module Behaviors::Service
  module ClassBehaviors
    # behavior_class_init is automatically run after the class is extended
    # and then removed from further use (via undef_method)
    def behavior_class_init
      has_many :service_overrides, :as => :target
      has_many :service_providers, :through => :service_overrides, :source => :service_provider
      
      class_eval(<<-EOS, __FILE__, __LINE__)
        @@service_relationships = {:parent => nil, :children => nil}
      EOS

      cattr_accessor :service_relationships
    end
    
    def service_parent_relationship association = :none
      service_relationships[:parent] = association.to_s.to_sym
    end

    def service_child_relationship association = :none
      service_relationships[:children] = association.to_s.to_sym
    end
  end

  module InstanceBehaviors
    
    def behavior_instance_init
      @none = nil
    end
    
    def service_parent *args
      rel = (service_relationships[:parent] == :none ? nil : service_relationships[:parent])
      send(rel, *args) unless rel.nil?
    end

    def service_children *args
      rel = (service_relationships[:children] == :none ? nil : service_relationships[:children])
      send(rel, *args) unless rel.nil?
    end
    
    def has_service_children?() !!service_children rescue false; end
    def has_service_parent?() !!service_parent rescue false; end
    
    alias :is_service_parent? :has_service_children?
    alias :is_service_child?  :has_service_parent?

    def can_override_service? type
      overridable = true
      while_walking_service_provider_lineage do |ancestor|
        parent_service = ancestor.service_override(type)
        overridable &= parent_service.overridable? unless parent_service.nil?
      end
      overridable
    end

    def service type
      provider = nil
      while_walking_service_provider_lineage do |ancestor|
        provider = ancestor.service_override(type).try(:provider)
        break unless provider.nil?
      end
      
      provider
    end

    def service_progenitor
      progenitor = nil
      while_walking_service_provider_lineage do |ancestor|
        progenitor = ancestor
      end
      progenitor
    end
    
    def service_dns_records=(v); end
    def service_dns_records
      services.values.collect { |s| s.hostline }.join "\n"
    end
    
    <commit_msg>skip services where provider is empty<commit_after>module Behaviors::Service
  module ClassBehaviors
    # behavior_class_init is automatically run after the class is extended
    # and then removed from further use (via undef_method)
    def behavior_class_init
      has_many :service_overrides, :as => :target
      has_many :service_providers, :through => :service_overrides, :source => :service_provider
      
      class_eval(<<-EOS, __FILE__, __LINE__)
        @@service_relationships = {:parent => nil, :children => nil}
      EOS

      cattr_accessor :service_relationships
    end
    
    def service_parent_relationship association = :none
      service_relationships[:parent] = association.to_s.to_sym
    end

    def service_child_relationship association = :none
      service_relationships[:children] = association.to_s.to_sym
    end
  end

  module InstanceBehaviors
    
    def behavior_instance_init
      @none = nil
    end
    
    def service_parent *args
      rel = (service_relationships[:parent] == :none ? nil : service_relationships[:parent])
      send(rel, *args) unless rel.nil?
    end

    def service_children *args
      rel = (service_relationships[:children] == :none ? nil : service_relationships[:children])
      send(rel, *args) unless rel.nil?
    end
    
    def has_service_children?() !!service_children rescue false; end
    def has_service_parent?() !!service_parent rescue false; end
    
    alias :is_service_parent? :has_service_children?
    alias :is_service_child?  :has_service_parent?

    def can_override_service? type
      overridable = true
      while_walking_service_provider_lineage do |ancestor|
        parent_service = ancestor.service_override(type)
        overridable &= parent_service.overridable? unless parent_service.nil?
      end
      overridable
    end

    def service type
      provider = nil
      while_walking_service_provider_lineage do |ancestor|
        provider = ancestor.service_override(type).try(:provider)
        break unless provider.nil?
      end
      
      provider
    end

    def service_progenitor
      progenitor = nil
      while_walking_service_provider_lineage do |ancestor|
        progenitor = ancestor
      end
      progenitor
    end
    
    def service_dns_records=(v); end
    def service_dns_records
      services.values.collect { |s| s.hostline rescue nil }.select{ |line| !line.nil? }.join "\n"
    end
    
    
{'fraction_non_alphanumeric': 0.07301389753163244, 'fraction_numerical': 0.0, 'mean_word_length': 3.062342038753159, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, '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': '947600', 'n_tokens_mistral': 1436, 'n_tokens_neox': 1395, 'n_words': 344}