<commit_before>module ContentfulModel
  class Base < Contentful::Entry
    include ContentfulModel::ChainableQueries

    def initialize(*args)
      super
      self.class.coercions ||= {}
    end

    #use method_missing to call fields on the model
    def method_missing(method)
      result = fields[:"#{method}"]
      if result.nil?
        raise NoMethodError, "No method or attribute #{method} for #{self}"
      else
        if self.class.coercions[method].nil?
          return result
        else
          return self.class::COERCIONS[self.class.coercions[method]].call(result)
        end
      end
    end

    def cache_key(*timestamp_names)
      if timestamp_names.present?
        raise ArgumentError, "ContentfulModel::Base models don't support named timestamps."
      end

      "#{self.class.to_s.underscore}/#{self.id}-#{self.updated_at.utc.to_s(:number)}"

    end

    class << self
      attr_accessor :content_type_id, :coercions

      def descendents
        ObjectSpace.each_object(Class).select { |klass| klass < self }
      end

      def add_entry_mapping
        unless ContentfulModel.configuration.entry_mapping.has_key?(@content_type_id)
          ContentfulModel.configuration.entry_mapping[@content_type_id] = Object.const_get(self.to_s.to_sym)
        end
      end

      def client<commit_msg>Raise NotImplementedError when saving a model.<commit_after>module ContentfulModel
  class Base < Contentful::Entry
    include ContentfulModel::ChainableQueries

    def initialize(*args)
      super
      self.class.coercions ||= {}
    end

    #use method_missing to call fields on the model
    def method_missing(method)
      result = fields[:"#{method}"]
      if result.nil?
        raise NoMethodError, "No method or attribute #{method} for #{self}"
      else
        if self.class.coercions[method].nil?
          return result
        else
          return self.class::COERCIONS[self.class.coercions[method]].call(result)
        end
      end
    end

    def cache_key(*timestamp_names)
      if timestamp_names.present?
        raise ArgumentError, "ContentfulModel::Base models don't support named timestamps."
      end

      "#{self.class.to_s.underscore}/#{self.id}-#{self.updated_at.utc.to_s(:number)}"

    end

    def save
      raise NotImplementedError, "Saving models isn't implemented; we need to use the Contentful Management API for that. Pull requests welcome!"
    end

    alias_method :create, :save

    class << self
      attr_accessor :content_type_id, :coercions

      def descendents
        ObjectSpace.each_object(Class).select { |klass| klass < self }
      end

      def add_entry_mapping
        unless ContentfulModel.configuration.entry_mapping.has_key?(@content_type_id)
          ContentfulModel.configuration.entry_mapping[@content_type_id] = Object.const_get(self.to_s.to_sym)
        end
      end

      def client
{'fraction_non_alphanumeric': 0.09050240880935995, 'fraction_numerical': 0.0, 'mean_word_length': 2.8300395256916997, 'pattern_counts': {'":': 0, '<': 11, '<?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': '2240132', 'n_tokens_mistral': 862, 'n_tokens_neox': 844, 'n_words': 195}