<commit_before># ActiveResource base class
# All models shoud extend this class

module MoySklad::Client
  class Base < ActiveResource::Base
    self.site = MoySklad.configuration.base_url
    self.format = Formatter.new
    self.user = MoySklad.configuration.user_name
    self.password = <PASSWORD>
    self.auth_type = :basic

    if ActiveResource::VERSION::STRING >= '4.0.0'
      self.include_format_in_path = false
      self.collection_parser = Collection
    end

    @@template_path = File.join(File.dirname(__FILE__), '..', 'models', 'templates')

    class << self

      def find(*args)
        # Little trick for correct baseclass name
        self.format.element_name = element_name.classify
        super(*args)
      end

      # Custom path builder
      def element_path(id, prefix_options = {}, query_options = nil)
        check_prefix_options(prefix_options)

        prefix_options, query_options = split_options(prefix_options) if query_options.nil?
        "#{prefix(prefix_options)}#{element_name.classify}/" \
        "#{URI.parser.escape id.to_s}#{query_string(query_options)}"
      end

      def new_element_path(prefix_options = {})
        "#{prefix(prefix_options)}#{element_name.classify}"
      end

      def collection_name
        @collection_name ||= "#{element_name.classify}/list"
      end

      if ActiveResource::VERSION::STRING < '4.0.0'
        def collection_path(prefix_options = {}, query_options = nil)
          check_prefix_options(prefix_options)
          prefix_options, query_options = split_options(prefix_options) if query_options.nil?
          "#{prefix(prefix_options)}#{collection_name}#{query_string(query_options)}"
        end
      end
    end

    # Override create method, this required because moysklad uses PUT instead of POST
    if ActiveResource::VERSION::STRING < '4.0.0'
      def create
        _create
      end

      def destroy
        _desroy
      end
    else
      def create
        run_callbacks :create do _create end
      end

      def destroy
        run_callbacks :destroy do _desroy end
      end
    end

    def save
      super
      self.error.is_a?(MoySklad::Client::Attribute::MissingAttr)
    end

    private

    def _create
      connection.put(new_element_path, encode, self.class.headers).tap do |response|
        self.id = id_from_response(response)
        load_attributes_from_response(response)
      end
    end

    def _destroy<commit_msg>desTroy yourself against the wall :p<commit_after># ActiveResource base class
# All models shoud extend this class

module MoySklad::Client
  class Base < ActiveResource::Base
    self.site = MoySklad.configuration.base_url
    self.format = Formatter.new
    self.user = MoySklad.configuration.user_name
    self.password = <PASSWORD>
    self.auth_type = :basic

    if ActiveResource::VERSION::STRING >= '4.0.0'
      self.include_format_in_path = false
      self.collection_parser = Collection
    end

    @@template_path = File.join(File.dirname(__FILE__), '..', 'models', 'templates')

    class << self

      def find(*args)
        # Little trick for correct baseclass name
        self.format.element_name = element_name.classify
        super(*args)
      end

      # Custom path builder
      def element_path(id, prefix_options = {}, query_options = nil)
        check_prefix_options(prefix_options)

        prefix_options, query_options = split_options(prefix_options) if query_options.nil?
        "#{prefix(prefix_options)}#{element_name.classify}/" \
        "#{URI.parser.escape id.to_s}#{query_string(query_options)}"
      end

      def new_element_path(prefix_options = {})
        "#{prefix(prefix_options)}#{element_name.classify}"
      end

      def collection_name
        @collection_name ||= "#{element_name.classify}/list"
      end

      if ActiveResource::VERSION::STRING < '4.0.0'
        def collection_path(prefix_options = {}, query_options = nil)
          check_prefix_options(prefix_options)
          prefix_options, query_options = split_options(prefix_options) if query_options.nil?
          "#{prefix(prefix_options)}#{collection_name}#{query_string(query_options)}"
        end
      end
    end

    # Override create method, this required because moysklad uses PUT instead of POST
    if ActiveResource::VERSION::STRING < '4.0.0'
      def create
        _create
      end

      def destroy
        _destroy
      end
    else
      def create
        run_callbacks :create do _create end
      end

      def destroy
        run_callbacks :destroy do _desroy end
      end
    end

    def save
      super
      self.error.is_a?(MoySklad::Client::Attribute::MissingAttr)
    end

    private

    def _create
      connection.put(new_element_path, encode, self.class.headers).tap do |response|
        self.id = id_from_response(response)
        load_attributes_from_response(response)
      end
    end

    def _destroy
{'fraction_non_alphanumeric': 0.09103811841038119, 'fraction_numerical': 0.0036496350364963502, 'mean_word_length': 2.806327160493827, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 7, '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': '3193564', 'n_tokens_mistral': 1466, 'n_tokens_neox': 1449, 'n_words': 316}