<commit_before>require 'eventbrite/api_object_class_methods'
require 'eventbrite/api_object_relationships'
module Eventbrite
  # @private
  # Class for generalizing API interactions
  class ApiObject
    extend Eventbrite::ApiObjectClassMethods
    include Eventbrite::ApiObjectRelationships
    
    attr_accessor :id, :owner
    # @private
    # Individual attribute tracking
    attr_accessor :attributes, :relations, :collections
    # @private
    # Dirty tracking
    attr_accessor :dirty, :dirty_relations, :dirty_collections
    
    def initialize(owner = false, hash = {})
      preinit
      @owner = owner if owner
      unless hash.empty?
        @id = hash.delete(:id)
        load(hash, true)
        init
      end
    end
    
    # @private
    # Initializes all attributes and dirtry tracking
    def preinit
      @attributes = @relations = @collections = {}
      @dirty = @dirty_relations = @dirty_collections = {}
    end
    
    # @private
    # Marks everything as clean.
    def clean!
      @dirty = @dirty_relations = @dirty_collections = {}
    end
    
    # @private
    # Callback after initialization
    def init; end
    
    # @private
    # Standard getter for attributes array
    def attribute_get(key);   @attributes[key];   end
   
    # @private
    # Standard setter for attributes, also tracking dirtiness
    def attribute_set(key, val, no_dirty = false)
      @dirty[key] = true if(@attributes[key] != val && !no_dirty)
      @attributes[key] = val
      after_attribute_set
    end
    
    # @private
    # Callback for when attributes are set.
    def after_attribute_set
    end
    
    # @private
    # Convert id to integer
    def id=(new_id,*args)
      @id = new_id.to_i
    end
    
    # Loads attributes and relations from a hash, 
    # or makes an API call to retrieve necessary data if load hash is empty
    #
    # The no_dirty attribute allows you to force a dirty tracking to recognize
    # the object as clean.
    def load(hash = {}, no_dirty = false)
      if hash.nil? || hash.size == 0
      
        response = Eventbrite.call("#{self.class.singlet_name}_get", prep_api_hash('get'))
        hash = response["#{self.class.singlet_name}"]
      end
      unless hash.nil? || hash.size == 0
        init_with_hash(hash, no_dirty)
        load_relations_with_hash(hash, no_dirty)
        load_collections_with_hash(hash, no_dirty)
      end
      clean! if no_dirty
      after_load(hash)
    end
    
    # @private
    # Loads all attributes from hash unless set to ignore.
    def init_with_hash(hash, no_dirty = false)
      if hash.class.name == "Array"
        hash = hash.first
      end

      @attributes ||= {}
      hash.each do |k, v| 
        self.__send__("#{k}=", v, no_dirty) unless (self.class.ignores.include?(k) ||
                                                    self.class.ignores.include?(k.to_sym)) ||
                                                    self.class.relations.include?(k) ||
                                                    self.class.relations.include?(k.to_sym) ||
                                                    self.class.collections.include?(k) ||
                                                    self.class.collections.include?(k.to_sym) ||
                                                    !self.respond_to?(k)
      end
    end
    
    # @private
    # A callback for after loads<commit_msg>Avoid setting nil fields.<commit_after>require 'eventbrite/api_object_class_methods'
require 'eventbrite/api_object_relationships'
module Eventbrite
  # @private
  # Class for generalizing API interactions
  class ApiObject
    extend Eventbrite::ApiObjectClassMethods
    include Eventbrite::ApiObjectRelationships
    
    attr_accessor :id, :owner
    # @private
    # Individual attribute tracking
    attr_accessor :attributes, :relations, :collections
    # @private
    # Dirty tracking
    attr_accessor :dirty, :dirty_relations, :dirty_collections
    
    def initialize(owner = false, hash = {})
      preinit
      @owner = owner if owner
      unless hash.empty?
        @id = hash.delete(:id)
        load(hash, true)
        init
      end
    end
    
    # @private
    # Initializes all attributes and dirtry tracking
    def preinit
      @attributes = @relations = @collections = {}
      @dirty = @dirty_relations = @dirty_collections = {}
    end
    
    # @private
    # Marks everything as clean.
    def clean!
      @dirty = @dirty_relations = @dirty_collections = {}
    end
    
    # @private
    # Callback after initialization
    def init; end
    
    # @private
    # Standard getter for attributes array
    def attribute_get(key);   @attributes[key];   end
   
    # @private
    # Standard setter for attributes, also tracking dirtiness
    def attribute_set(key, val, no_dirty = false)
      @dirty[key] = true if(@attributes[key] != val && !no_dirty)
      @attributes[key] = val
      after_attribute_set
    end
    
    # @private
    # Callback for when attributes are set.
    def after_attribute_set
    end
    
    # @private
    # Convert id to integer
    def id=(new_id,*args)
      @id = new_id.to_i
    end
    
    # Loads attributes and relations from a hash, 
    # or makes an API call to retrieve necessary data if load hash is empty
    #
    # The no_dirty attribute allows you to force a dirty tracking to recognize
    # the object as clean.
    def load(hash = {}, no_dirty = false)
      if hash.nil? || hash.size == 0
      
        response = Eventbrite.call("#{self.class.singlet_name}_get", prep_api_hash('get'))
        hash = response["#{self.class.singlet_name}"]
      end
      unless hash.nil? || hash.size == 0
        init_with_hash(hash, no_dirty)
        load_relations_with_hash(hash, no_dirty)
        load_collections_with_hash(hash, no_dirty)
      end
      clean! if no_dirty
      after_load(hash)
    end
    
    # @private
    # Loads all attributes from hash unless set to ignore.
    def init_with_hash(hash, no_dirty = false)
      if hash.class.name == "Array"
        hash = hash.first
      end

      @attributes ||= {}
      hash.each do |k, v| 
        self.__send__("#{k}=", v, no_dirty) unless (v.nil? || v.blank? ||
                                                    self.class.ignores.include?(k) ||
                                                    self.class.ignores.include?(k.to_sym)) ||
                                                    self.class.relations.include?(k) ||
                                                    self.class.relations.include?(k.to_sym) ||
                                                    self.class.collections.include?(k) ||
                                                    self.class.collections.include?(k.to_sym) ||
                                                    !self.respond_to?(k)
      end
    end
    
    # @private
    # A callback for after loads
{'fraction_non_alphanumeric': 0.0898730525100981, 'fraction_numerical': 0.0005770340450086555, 'mean_word_length': 1.885143570536829, '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': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1656327', 'n_tokens_mistral': 1936, 'n_tokens_neox': 1925, 'n_words': 506}