Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #4084: 4084_quote_scope_condition_value.diff

File 4084_quote_scope_condition_value.diff, 1.5 kB (added by Caio Chassot <caio@v2studio.com>, 2 years ago)
  • lib/active_record/acts/list.rb

    old new  
    3636 
    3737          configuration[:scope] = "#{configuration[:scope]}_id".intern if configuration[:scope].is_a?(Symbol) && configuration[:scope].to_s !~ /_id$/ 
    3838           
    39           if configuration[:scope].is_a?(Symbol) 
    40             scope_condition_method = %( 
    41               def scope_condition 
    42                 if #{configuration[:scope].to_s}.nil? 
    43                   "#{configuration[:scope].to_s} IS NULL" 
    44                 else 
    45                   "#{configuration[:scope].to_s} = \#{#{configuration[:scope].to_s}}" 
    46                 end 
    47               end 
    48             ) 
    49           else 
    50             scope_condition_method = "def scope_condition() \"#{configuration[:scope]}\" end" 
     39          define_method :scope_condition do 
     40            condition = configuration[:scope] 
     41            return eval("\"#{condition}\"") unless condition.is_a?(Symbol) 
     42            value = send(condition) 
     43            value.nil? ? "#{condition} IS NULL" : "#{condition} = #{quote(value)}" 
    5144          end 
    5245           
    5346          class_eval <<-EOV 
     
    6154              '#{configuration[:column]}' 
    6255            end 
    6356             
    64             #{scope_condition_method} 
    65              
    6657            after_destroy  :remove_from_list 
    6758            before_create  :add_to_list_bottom 
    6859          EOV