<commit_before>module Traits
  module Controller
    module Resource
      module ClassMethods
        def self.extended(reciever)
          reciever.before_filter "find_#{reciever.controller_name.singularize}"
        end
        
        def singular_name
          controller_name.singularize
        end
        
        def set_scope(scope, options = {})
          class_eval do
            attr_accessor_with_default :collection_scope, { :scope => scope, :condition => options }
          end
        end
        
        def set_options(options = {})
          class_eval do
            attr_accessor_with_default :_custom_options, options
          end
        end
        
        def define_actions(*args)
          args.map {|v| v.to_s.classify }.each {|v| self.send(:include, "Traits::Controller::Actions::#{v}".constantize) }
        end
      end
      
      module InstanceMethods
        def self.included(receiver)
          receiver.send(:define_method, "find_#{receiver.singular_name}") do
            instance_variable_set("@#{singular_name}", resource_class.find(params[:id])) if params[:id]
          end
        end
        
        def singular_name
           controller_name.singularize
        end
        
        def resource_class
          singular_name.classify.constantize
        end
        
        def proxy_klass
          return resource_class unless (defined? collection_scope)
          return instance_eval(collection_scope[:scope]) if collection_scope[:condition].blank? || (
                   (Array.wrap(collection_scope[:condition][:only]).include?(action_name.to_sym) &&
                   !Array.wrap(collection_scope[:condition][:except]).include?(action_name.to_sym))
                 )
          return resource_class
        end
        
        def response_with_options(resource)
           serialize_options  = {}
           begin
             serialize_options = resource_class.const_get(:SerializeOptions)
           rescue
           end
           respond_with resource, serialize_options
        end

      end
      
      def self.included(receiver)
        receiver.extend         ClassMethods
        receiver.send :include, InstanceMethods
      end
    end
  end
end<commit_msg>fixed wrong except-action detection<commit_after>module Traits
  module Controller
    module Resource
      module ClassMethods
        def self.extended(reciever)
          reciever.before_filter "find_#{reciever.controller_name.singularize}"
        end
        
        def singular_name
          controller_name.singularize
        end
        
        def set_scope(scope, options = {})
          class_eval do
            attr_accessor_with_default :collection_scope, { :scope => scope, :condition => options }
          end
        end
        
        def set_options(options = {})
          class_eval do
            attr_accessor_with_default :_custom_options, options
          end
        end
        
        def define_actions(*args)
          args.map {|v| v.to_s.classify }.each {|v| self.send(:include, "Traits::Controller::Actions::#{v}".constantize) }
        end
      end
      
      module InstanceMethods
        def self.included(receiver)
          receiver.send(:define_method, "find_#{receiver.singular_name}") do
            instance_variable_set("@#{singular_name}", resource_class.find(params[:id])) if params[:id]
          end
        end
        
        def singular_name
           controller_name.singularize
        end
        
        def resource_class
          singular_name.classify.constantize
        end
        
        def proxy_klass
          return resource_class if !defined?(collection_scope) 
          
          action  = action_name.to_sym
          only    = Array.wrap(collection_scope[:condition][:only])
          except  = Array.wrap(collection_scope[:condition][:except])
          
          return resource_class if except.include?(action)
                  
          return instance_eval(collection_scope[:scope]) if collection_scope[:condition].blank? ||
                    (only.include?(action) && !except.include?(action))
                    
          return resource_class
        end
        
        def response_with_options(resource)
           serialize_options  = {}
           begin
             serialize_options = resource_class.const_get(:SerializeOptions)
           rescue
           end
           respond_with resource, serialize_options
        end

      end
      
      def self.included(receiver)
        receiver.extend         ClassMethods
        receiver.send :include, InstanceMethods
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.0759656652360515, 'fraction_numerical': 0.0, 'mean_word_length': 1.8455433455433456, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3290226', 'n_tokens_mistral': 1199, 'n_tokens_neox': 1206, 'n_words': 233}