<commit_before>class CapsuleCRM::Party
  include CapsuleCRM::Taggable

  include CapsuleCRM::Associations::HasMany

  has_many :histories, class_name: 'CapsuleCRM::History'

  def self.all(options = {})
    attributes = CapsuleCRM::Connection.get('/api/party', options)
    init_collection(attributes['parties'])
  end

  def self.find(id)
    attributes = CapsuleCRM::Connection.get("/api/party/#{id}")
    party_classes[attributes.keys.first].constantize.new(
      attributes[attributes.keys.first]
    )
  end

  private

  def self.init_collection(collection)
    CapsuleCRM::ResultsProxy.new(
      collection.map do |key, value|
        [collection[key]].flatten.map do |attrs|
          party_classes[key].constantize.new(attrs)
        end.flatten
      end.flatten
    )
  end

  def self.party_classes
    {
      person:       'CapsuleCRM::Person',
      organisation: 'CapsuleCRM::Organization'
    }.stringify_keys
  end
end
<commit_msg>Add source to party histories association so that #build works<commit_after>class CapsuleCRM::Party
  include CapsuleCRM::Taggable

  include CapsuleCRM::Associations::HasMany

  has_many :histories, class_name: 'CapsuleCRM::History', source: :party

  def self.all(options = {})
    attributes = CapsuleCRM::Connection.get('/api/party', options)
    init_collection(attributes['parties'])
  end

  def self.find(id)
    attributes = CapsuleCRM::Connection.get("/api/party/#{id}")
    party_classes[attributes.keys.first].constantize.new(
      attributes[attributes.keys.first]
    )
  end

  private

  def self.init_collection(collection)
    CapsuleCRM::ResultsProxy.new(
      collection.map do |key, value|
        [collection[key]].flatten.map do |attrs|
          party_classes[key].constantize.new(attrs)
        end.flatten
      end.flatten
    )
  end

  def self.party_classes
    {
      person:       'CapsuleCRM::Person',
      organisation: 'CapsuleCRM::Organization'
    }.stringify_keys
  end
end

{'fraction_non_alphanumeric': 0.11692933401118455, 'fraction_numerical': 0.0, 'mean_word_length': 3.5555555555555554, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5182949', 'n_tokens_mistral': 652, 'n_tokens_neox': 638, 'n_words': 107}