<commit_before>class Yogo::BaseController < InheritedResources::Base
  respond_to :html, :json
  
  extend Yogo::Chainable
  self.responder = Class.new(::ActionController::Responder)
  
  
  extendable do
    def with_responder(&block)
      self.responder = Class.new(self.responder || ::ActionController::Responder)
      self.responder.extend(Yogo::Chainable)
      self.responder.chainable(&block)
      self.responder
    end
  end
  
  chainable do
    def parsed_body(format=request.content_type)
      format_method = "body_#{format.to_sym}".to_sym
      
      if respond_to?(format_method)
        begin
          send(format_method)
        rescue
          false
        end
      else
        false
      end
    end
    
    protected
    
    def body_json
      JSON.parse(request.body.string)
    end
  end
  
  chainable do
    def build_resource
      if data = parsed_body
        get_resource_ivar || set_resource_ivar(end_of_association_chain.send(method_for_build, data || {}))
      else
        super
      end
    end
  end
  
  with_responder do
    include Responders::FlashResponder
    include Responders::HttpCacheResponder
  end<commit_msg>filter out attributes that the model does not use<commit_after>class Yogo::BaseController < InheritedResources::Base
  respond_to :html, :json
  
  extend Yogo::Chainable
  self.responder = Class.new(::ActionController::Responder)
  
  
  extendable do
    def with_responder(&block)
      self.responder = Class.new(self.responder || ::ActionController::Responder)
      self.responder.extend(Yogo::Chainable)
      self.responder.chainable(&block)
      self.responder
    end
  end
  
  chainable do
    def parsed_body(format=request.content_type)
      format_method = "body_#{format.to_sym}".to_sym
      
      if respond_to?(format_method)
        begin
          send(format_method)
        rescue
          false
        end
      else
        false
      end
    end
    
    protected
    
    def body_json
      JSON.parse(request.body.string)
    end
  end
  
  chainable do
    def build_resource
      if data = parsed_body
        get_resource_ivar || set_resource_ivar(end_of_association_chain.send(method_for_build, data || {}))
      else
        super
      end
    end
    
    def update_resource(object, attributes)
      # debugger
      attributes = attributes || parsed_body
      attributes.delete('id')
      attr_keys = object.attributes.keys.map{|key| key.to_s }
      valid_attributes = attributes.inject({}) {|h,(k,v)| h[k]=v if attr_keys.include?(k); h }
      object.attributes = valid_attributes
      object.save
    end
  end
  
  with_responder do
    include Responders::FlashResponder
    include Responders::HttpCacheResponder
  end
{'fraction_non_alphanumeric': 0.08081543502002184, 'fraction_numerical': 0.0, 'mean_word_length': 2.573472041612484, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6599020', 'n_tokens_mistral': 857, 'n_tokens_neox': 848, 'n_words': 163}