<commit_before>module Merb
  module ResourceController
    
    class ResourceControllerException < Exception; end
    class WebMethodsNotAvailable < ResourceControllerException; end
    class InvalidRoute < ResourceControllerException; end
    
    module Mixin
  
      module ClassMethods
    
        # DEFAULTS to the following if no block is given
        # ----------------------------------------------
        # controlling :projects do |p|
        #   p.action :index,   :provides => [ :json, :yaml ], :on => :collection,
        #   p.action :show
        #   p.action :new,     :provides => :html
        #   p.action :edit,    :provides => :html
        #   p.action :create  
        #   p.action :update
        #   p.action :destroy
        # end
        def controlling(name, options = {})
          options = { :defaults => true, :flash => true }.merge!(options)
          @resource_proxy = Merb::ResourceController::ResourceProxy.new(name, options)
          yield @resource_proxy if block_given?
          class_inheritable_reader :resource_proxy
          include InstanceMethods
          include FlashSupport if options[:flash]
          @resource_proxy.actions.each do |a|
            include Merb::ResourceController::Actions.const_get("#{a[:name].to_s.camel_case}")
            show_action(a[:name])
          end
        end
    
      end
  
      module InstanceMethods
        
        protected
    
        def resource_proxy
          self.class.resource_proxy
        end
        
        
        def load_collection
          resource_proxy.all
        end
        
        def load_member(id)
          resource_proxy.get(id)
        end
        
        
        def collection=(obj)
          instance_variable_set("@#{collection_name}", obj)
        end
        
        def collection
          instance_variable_get("@#{collection_name}")
        end
        
        
        def new_member(attributes = {})
          resource_proxy.new(attributes)
        end
        
        def member=(obj)
          instance_variable_set("@#{member_name}", obj)
        end
        
        def member
          instance_variable_get("@#{member_name}")
        end
        
        
        def collection_name
          resource_proxy.collection_name
        end
        
        def member_name
          resource_proxy.member_name
        end
        
        
        def flash_supported?
          self.kind_of?(FlashSupport)
        end
    
      end
      
      module FlashSupport
        
        protected
        
        def successful_create_messages
          { :notice => "#{member.class.name} was successfully created" }
        end
                
        def failed_create_messages
          { :error => "Failed to create new #{member.class.name}" }
        end
        
                
        def successful_update_messages
          { :notice => "#{member.class.name} was successfully updated" }
        end
                
        def failed_update_messages
          { :error => "Failed to update #{member.class.name}" }
        end
                
                
        def successful_destroy_messages
          { :notice => "#{member.class.name} was successfully destroyed" }
        end
                
        def failed_destroy_messages
          { :error => "Failed to destroy #{member.class.name}" }
        end
        
      end
  
    end
  
  end
end<commit_msg>Allow to pass conditions into load_collection.<commit_after>module Merb
  module ResourceController
    
    class ResourceControllerException < Exception; end
    class WebMethodsNotAvailable < ResourceControllerException; end
    class InvalidRoute < ResourceControllerException; end
    
    module Mixin
  
      module ClassMethods
    
        # DEFAULTS to the following if no block is given
        # ----------------------------------------------
        # controlling :projects do |p|
        #   p.action :index,   :provides => [ :json, :yaml ], :on => :collection,
        #   p.action :show
        #   p.action :new,     :provides => :html
        #   p.action :edit,    :provides => :html
        #   p.action :create  
        #   p.action :update
        #   p.action :destroy
        # end
        def controlling(name, options = {})
          options = { :defaults => true, :flash => true }.merge!(options)
          @resource_proxy = Merb::ResourceController::ResourceProxy.new(name, options)
          yield @resource_proxy if block_given?
          class_inheritable_reader :resource_proxy
          include InstanceMethods
          include FlashSupport if options[:flash]
          @resource_proxy.actions.each do |a|
            include Merb::ResourceController::Actions.const_get("#{a[:name].to_s.camel_case}")
            show_action(a[:name])
          end
        end
    
      end
  
      module InstanceMethods
        
        protected
    
        def resource_proxy
          self.class.resource_proxy
        end
        
        
        def load_collection(conditions = {})
          resource_proxy.all(conditions)
        end
        
        def load_member(id)
          resource_proxy.get(id)
        end
        
        
        def collection=(obj)
          instance_variable_set("@#{collection_name}", obj)
        end
        
        def collection
          instance_variable_get("@#{collection_name}")
        end
        
        
        def new_member(attributes = {})
          resource_proxy.new(attributes)
        end
        
        def member=(obj)
          instance_variable_set("@#{member_name}", obj)
        end
        
        def member
          instance_variable_get("@#{member_name}")
        end
        
        
        def collection_name
          resource_proxy.collection_name
        end
        
        def member_name
          resource_proxy.member_name
        end
        
        
        def flash_supported?
          self.kind_of?(FlashSupport)
        end
    
      end
      
      module FlashSupport
        
        protected
        
        def successful_create_messages
          { :notice => "#{member.class.name} was successfully created" }
        end
                
        def failed_create_messages
          { :error => "Failed to create new #{member.class.name}" }
        end
        
                
        def successful_update_messages
          { :notice => "#{member.class.name} was successfully updated" }
        end
                
        def failed_update_messages
          { :error => "Failed to update #{member.class.name}" }
        end
                
                
        def successful_destroy_messages
          { :notice => "#{member.class.name} was successfully destroyed" }
        end
                
        def failed_destroy_messages
          { :error => "Failed to destroy #{member.class.name}" }
        end
        
      end
  
    end
  
  end
end
{'fraction_non_alphanumeric': 0.08936292879792447, 'fraction_numerical': 0.0, 'mean_word_length': 1.4615111741752393, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 27, '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': '6340049', 'n_tokens_mistral': 1729, 'n_tokens_neox': 1751, 'n_words': 396}