]> source.dussan.org Git - redmine.git/commitdiff
Use lambda form in model scopes (#12499)
authorJean-Baptiste Barth <jeanbaptiste.barth@gmail.com>
Fri, 7 Dec 2012 10:12:47 +0000 (10:12 +0000)
committerJean-Baptiste Barth <jeanbaptiste.barth@gmail.com>
Fri, 7 Dec 2012 10:12:47 +0000 (10:12 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10949 e93f8b46-1217-0410-a6f0-8f06a7374b81

12 files changed:
app/models/custom_field.rb
app/models/enumeration.rb
app/models/group.rb
app/models/issue.rb
app/models/issue_status.rb
app/models/principal.rb
app/models/project.rb
app/models/role.rb
app/models/tracker.rb
app/models/user.rb
app/models/version.rb
app/models/wiki_page.rb

index 9f17bff02ee21850e8f4f88c76eef2489d0680fd..9d40ebd7add350f33fcd0f7a17d02a6b62cbc0ed 100644 (file)
@@ -30,7 +30,7 @@ class CustomField < ActiveRecord::Base
   validate :validate_custom_field
   before_validation :set_searchable
 
-  scope :sorted, order("#{table_name}.position ASC")
+  scope :sorted, lambda { order("#{table_name}.position ASC") }
 
   CUSTOM_FIELDS_TABS = [
     {:name => 'IssueCustomField', :partial => 'custom_fields/index',
index d3454021fb57c32055fc53fff3dc1b1af497a241..1c4a7a4141b4afb694491aae7c28773b4a5690d1 100644 (file)
@@ -35,9 +35,9 @@ class Enumeration < ActiveRecord::Base
   validates_uniqueness_of :name, :scope => [:type, :project_id]
   validates_length_of :name, :maximum => 30
 
-  scope :shared, where(:project_id => nil)
-  scope :sorted, order("#{table_name}.position ASC")
-  scope :active, where(:active => true)
+  scope :shared, lambda { where(:project_id => nil) }
+  scope :sorted, lambda { order("#{table_name}.position ASC") }
+  scope :active, lambda { where(:active => true) }
   scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)}
 
   def self.default
index f8b1ee639cd7ab2ecf775b9268bb02f892d87b2f..fec5b8a835ee668c36f09b3355d079291f5c2cf6 100644 (file)
@@ -29,7 +29,7 @@ class Group < Principal
 
   before_destroy :remove_references_before_destroy
 
-  scope :sorted, order("#{table_name}.lastname ASC")
+  scope :sorted, lambda { order("#{table_name}.lastname ASC") }
 
   safe_attributes 'name',
     'user_ids',
index 4b60843c7fd23b11381c3b45bcf79100b8b2fc79..7ba0ba207284f686e9732f6c6a0e07e19e0878d0 100644 (file)
@@ -79,9 +79,9 @@ class Issue < ActiveRecord::Base
     {:conditions => ["#{IssueStatus.table_name}.is_closed = ?", is_closed], :include => :status}
   }
 
-  scope :recently_updated, :order => "#{Issue.table_name}.updated_on DESC"
-  scope :on_active_project, :include => [:status, :project, :tracker],
-                            :conditions => ["#{Project.table_name}.status=#{Project::STATUS_ACTIVE}"]
+  scope :recently_updated, lambda { { :order => "#{Issue.table_name}.updated_on DESC" } }
+  scope :on_active_project, lambda { { :include => [:status, :project, :tracker],
+                                       :conditions => ["#{Project.table_name}.status=#{Project::STATUS_ACTIVE}"] } }
 
   before_create :default_assign
   before_save :close_duplicates, :update_done_ratio_from_issue_status, :force_updated_on_change
index fe1615706c36b88a306e2cf75bab9d5f4e6ceb36..b66c8d3a14734983a0fa92c55b73142a369aaf37 100644 (file)
@@ -28,7 +28,7 @@ class IssueStatus < ActiveRecord::Base
   validates_length_of :name, :maximum => 30
   validates_inclusion_of :default_done_ratio, :in => 0..100, :allow_nil => true
 
-  scope :sorted, order("#{table_name}.position ASC")
+  scope :sorted, lambda { order("#{table_name}.position ASC") }
   scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)}
 
   def update_default
index dfafe9de97c487a5ed0e1afe6277b46fac67b7a0..044f256ad4cac61400fdd268a984e425266481ef 100644 (file)
@@ -24,7 +24,7 @@ class Principal < ActiveRecord::Base
   has_many :issue_categories, :foreign_key => 'assigned_to_id', :dependent => :nullify
 
   # Groups and active users
-  scope :active, :conditions => "#{Principal.table_name}.status = 1"
+  scope :active, lambda { { :conditions => "#{Principal.table_name}.status = 1" } }
 
   scope :like, lambda {|q|
     q = q.to_s
index 9f4b07d49fc5ac84c868ea40fe235c84bd2efe5d..5e26bd7f67bf6e772906b1f881e0ce091c2418f7 100644 (file)
@@ -85,9 +85,9 @@ class Project < ActiveRecord::Base
   before_destroy :delete_all_members
 
   scope :has_module, lambda { |mod| { :conditions => ["#{Project.table_name}.id IN (SELECT em.project_id FROM #{EnabledModule.table_name} em WHERE em.name=?)", mod.to_s] } }
-  scope :active, { :conditions => "#{Project.table_name}.status = #{STATUS_ACTIVE}"}
+  scope :active, lambda { { :conditions => "#{Project.table_name}.status = #{STATUS_ACTIVE}" } }
   scope :status, lambda {|arg| arg.blank? ? {} : {:conditions => {:status => arg.to_i}} }
-  scope :all_public, { :conditions => { :is_public => true } }
+  scope :all_public, lambda { { :conditions => { :is_public => true } } }
   scope :visible, lambda {|*args| {:conditions => Project.visible_condition(args.shift || User.current, *args) }}
   scope :allowed_to, lambda {|*args| 
     user = User.current
index 15ed0e10d5f89a26d73bd587381fa5f41a762308..d393582c02535670b1ddea21320febf9aedfceb5 100644 (file)
@@ -39,8 +39,8 @@ class Role < ActiveRecord::Base
     ['own', :label_issues_visibility_own]
   ]
 
-  scope :sorted, order("#{table_name}.builtin ASC, #{table_name}.position ASC")
-  scope :givable, order("#{table_name}.position ASC").where(:builtin => 0)
+  scope :sorted, lambda { order("#{table_name}.builtin ASC, #{table_name}.position ASC") }
+  scope :givable, lambda { order("#{table_name}.position ASC").where(:builtin => 0) }
   scope :builtin, lambda { |*args|
     compare = (args.first == true ? 'not' : '')
     where("#{compare} builtin = 0")
index 9b3f6afe673266e0870ab9a0bcf3583b953867db..3b7558701fd2f8767bf518c0a7a47e674ead8dd9 100644 (file)
@@ -41,7 +41,7 @@ class Tracker < ActiveRecord::Base
   validates_uniqueness_of :name
   validates_length_of :name, :maximum => 30
 
-  scope :sorted, order("#{table_name}.position ASC")
+  scope :sorted, lambda { order("#{table_name}.position ASC") }
   scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)}
 
   def to_s; name end
index 0cf2c931407370b90e461dd41841ed42b6d2154a..32b7d4499ffac7b60167cf1383b64dd62ac61817 100644 (file)
@@ -82,7 +82,7 @@ class User < Principal
   has_one :api_token, :class_name => 'Token', :conditions => "action='api'"
   belongs_to :auth_source
 
-  scope :logged, :conditions => "#{User.table_name}.status <> #{STATUS_ANONYMOUS}"
+  scope :logged, lambda { { :conditions => "#{User.table_name}.status <> #{STATUS_ANONYMOUS}" } }
   scope :status, lambda {|arg| arg.blank? ? {} : {:conditions => {:status => arg.to_i}} }
 
   acts_as_customizable
index dbcd317e92a38f9c290798cc205a937a299e08c2..07d312ab957b72435e72155086351d62a564b361 100644 (file)
@@ -36,7 +36,7 @@ class Version < ActiveRecord::Base
   validate :validate_version
 
   scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)}
-  scope :open, where(:status => 'open')
+  scope :open, lambda { where(:status => 'open') }
   scope :visible, lambda {|*args|
     includes(:project).where(Project.allowed_to_condition(args.first || User.current, :view_issues))
   }
index 115b23d6d7396b59d76ef69d1ace15258e0e6dfb..45954a08d7dd283611d09fd5fa234c9932253320 100644 (file)
@@ -49,10 +49,10 @@ class WikiPage < ActiveRecord::Base
   before_save    :handle_redirects
 
   # eager load information about last updates, without loading text
-  scope :with_updated_on, {
+  scope :with_updated_on, lambda { {
     :select => "#{WikiPage.table_name}.*, #{WikiContent.table_name}.updated_on, #{WikiContent.table_name}.version",
     :joins => "LEFT JOIN #{WikiContent.table_name} ON #{WikiContent.table_name}.page_id = #{WikiPage.table_name}.id"
-  }
+  } }
 
   # Wiki pages that are protected by default
   DEFAULT_PROTECTED_PAGES = %w(sidebar)