]> source.dussan.org Git - redmine.git/commitdiff
model: replace Rails2 "named_scope" to Rails3 "scope"
authorToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Thu, 26 Apr 2012 23:51:10 +0000 (23:51 +0000)
committerToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Thu, 26 Apr 2012 23:51:10 +0000 (23:51 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9537 e93f8b46-1217-0410-a6f0-8f06a7374b81

19 files changed:
app/models/board.rb
app/models/changeset.rb
app/models/document.rb
app/models/enumeration.rb
app/models/issue.rb
app/models/issue_category.rb
app/models/issue_status.rb
app/models/journal.rb
app/models/message.rb
app/models/news.rb
app/models/principal.rb
app/models/project.rb
app/models/query.rb
app/models/role.rb
app/models/time_entry.rb
app/models/tracker.rb
app/models/user.rb
app/models/version.rb
app/models/wiki_page.rb

index 40fd356737b46ea69eb01ef82e2ca11d71761e4f..624ef4e05a9f292856bb02f3006074f9a5abda22 100644 (file)
@@ -28,7 +28,7 @@ class Board < ActiveRecord::Base
   validates_length_of :name, :maximum => 30
   validates_length_of :description, :maximum => 255
 
-  named_scope :visible, lambda {|*args| { :include => :project,
+  scope :visible, lambda {|*args| { :include => :project,
                                           :conditions => Project.allowed_to_condition(args.shift || User.current, :view_messages, *args) } }
 
   safe_attributes 'name', 'description', 'move_to'
index ea3d61d87cd6795d3af436defbc1f52d932092f5..89825c652e0dd1edb904ae5b7d2f7f6fe3533a45 100644 (file)
@@ -49,7 +49,8 @@ class Changeset < ActiveRecord::Base
   validates_uniqueness_of :revision, :scope => :repository_id
   validates_uniqueness_of :scmid, :scope => :repository_id, :allow_nil => true
 
-  named_scope :visible, lambda {|*args| { :include => {:repository => :project},
+  scope :visible,
+     lambda {|*args| { :include => {:repository => :project},
                                           :conditions => Project.allowed_to_condition(args.shift || User.current, :view_changesets, *args) } }
 
   after_create :scan_for_issues
index d4a89ffd9f5037376781a62abb4e25220367e7ea..1f8e72c52db72ec48ff00c667d3370489651a927 100644 (file)
@@ -30,7 +30,7 @@ class Document < ActiveRecord::Base
   validates_presence_of :project, :title, :category
   validates_length_of :title, :maximum => 60
 
-  named_scope :visible, lambda {|*args| { :include => :project,
+  scope :visible, lambda {|*args| { :include => :project,
                                           :conditions => Project.allowed_to_condition(args.shift || User.current, :view_documents, *args) } }
 
   safe_attributes 'category_id', 'title', 'description'
index d532c78beee8206066e7fcde7a0215bea0361595..f1d484d88fd5647ced08ce1c536170d6c6bf8125 100644 (file)
@@ -35,9 +35,9 @@ class Enumeration < ActiveRecord::Base
   validates_uniqueness_of :name, :scope => [:type, :project_id]
   validates_length_of :name, :maximum => 30
 
-  named_scope :shared, :conditions => { :project_id => nil }
-  named_scope :active, :conditions => { :active => true }
-  named_scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}}
+  scope :shared, :conditions => { :project_id => nil }
+  scope :active, :conditions => { :active => true }
+  scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}}
 
   def self.default
     # Creates a fake default scope so Enumeration.default will check
index a81dda16fbb83d76d50dedf416109d88c10b5980..b8ea90efd453465c8cabb7e0b057f466fc6069fd 100644 (file)
@@ -60,18 +60,19 @@ class Issue < ActiveRecord::Base
   validates_numericality_of :estimated_hours, :allow_nil => true
   validate :validate_issue
 
-  named_scope :visible, lambda {|*args| { :include => :project,
-                                          :conditions => Issue.visible_condition(args.shift || User.current, *args) } }
+  scope :visible,
+        lambda {|*args| { :include => :project,
+                          :conditions => Issue.visible_condition(args.shift || User.current, *args) } }
 
-  named_scope :open, lambda {|*args|
+  scope :open, lambda {|*args|
     is_closed = args.size > 0 ? !args.first : false
     {:conditions => ["#{IssueStatus.table_name}.is_closed = ?", is_closed], :include => :status}
   }
 
-  named_scope :recently_updated, :order => "#{Issue.table_name}.updated_on DESC"
-  named_scope :with_limit, lambda { |limit| { :limit => limit} }
-  named_scope :on_active_project, :include => [:status, :project, :tracker],
-                                  :conditions => ["#{Project.table_name}.status=#{Project::STATUS_ACTIVE}"]
+  scope :recently_updated, :order => "#{Issue.table_name}.updated_on DESC"
+  scope :with_limit, lambda { |limit| { :limit => limit} }
+  scope :on_active_project, :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
index 162e7dc7244d41d4568941e58e61a555e625dbb1..3ff0d0591d76351cac47796b3b4f1810a4e15d6f 100644 (file)
@@ -27,7 +27,7 @@ class IssueCategory < ActiveRecord::Base
   
   safe_attributes 'name', 'assigned_to_id'
 
-  named_scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}}
+  scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}}
 
   alias :destroy_without_reassign :destroy
 
index 600d0cbf46098cd693214fb3ffaa997dea408355..d69aee079cf43404119425f708586bf222fa1cf1 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
 
-  named_scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}}
+  scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}}
 
   def update_default
     IssueStatus.update_all("is_default=#{connection.quoted_false}", ['id <> ?', id]) if self.is_default?
index fe8a432b6ee9b80f9368dd33e6cc111776c0e044..73db1f62d9d06d61228802ba17cbfe511ab0914f 100644 (file)
@@ -37,7 +37,7 @@ class Journal < ActiveRecord::Base
                                               :conditions => "#{Journal.table_name}.journalized_type = 'Issue' AND" +
                                                              " (#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')"}
 
-  named_scope :visible, lambda {|*args| {
+  scope :visible, lambda {|*args| {
     :include => {:issue => :project},
     :conditions => Issue.visible_condition(args.shift || User.current, *args)
   }}
index 5d028870d36b25092e44e27bb6980527fe004783..5294a655ec8baf5c2dfd312adf6586ef3d5d8cbf 100644 (file)
@@ -45,7 +45,7 @@ class Message < ActiveRecord::Base
   after_update :update_messages_board
   after_destroy :reset_board_counters
 
-  named_scope :visible, lambda {|*args| { :include => {:board => :project},
+  scope :visible, lambda {|*args| { :include => {:board => :project},
                                           :conditions => Project.allowed_to_condition(args.shift || User.current, :view_messages, *args) } }
 
   safe_attributes 'subject', 'content'
index 1f7c6f4a76b8d774f79186c573f75781f08dd722..bf1cc4f80fe7b471d944a8af1f36f15736562aec 100644 (file)
@@ -34,7 +34,7 @@ class News < ActiveRecord::Base
 
   after_create :add_author_as_watcher
 
-  named_scope :visible, lambda {|*args| {
+  scope :visible, lambda {|*args| {
     :include => :project,
     :conditions => Project.allowed_to_condition(args.shift || User.current, :view_news, *args)
   }}
index de653998682be670af31219336a316fbb92243cb..f2bec0e2652871358c65533aaa8e53cfe0e31908 100644 (file)
@@ -24,9 +24,9 @@ class Principal < ActiveRecord::Base
   has_many :issue_categories, :foreign_key => 'assigned_to_id', :dependent => :nullify
 
   # Groups and active users
-  named_scope :active, :conditions => "#{Principal.table_name}.status = 1"
+  scope :active, :conditions => "#{Principal.table_name}.status = 1"
 
-  named_scope :like, lambda {|q|
+  scope :like, lambda {|q|
     if q.blank?
       {}
     else
@@ -44,7 +44,7 @@ class Principal < ActiveRecord::Base
   }
 
   # Principals that are members of a collection of projects
-  named_scope :member_of, lambda {|projects|
+  scope :member_of, lambda {|projects|
     projects = [projects] unless projects.is_a?(Array)
     if projects.empty?
       {:conditions => "1=0"}
@@ -54,7 +54,7 @@ class Principal < ActiveRecord::Base
     end
   }
   # Principals that are not members of projects
-  named_scope :not_member_of, lambda {|projects|
+  scope :not_member_of, lambda {|projects|
     projects = [projects] unless projects.is_a?(Array)
     if projects.empty?
       {:conditions => "1=0"}
index 6dfe95cc4672736396b36f66199d1a8ccf3b7db4..8006d5818ea5394f32abbc46ea249e8dc22ef210 100644 (file)
@@ -82,12 +82,12 @@ class Project < ActiveRecord::Base
 
   before_destroy :delete_all_members
 
-  named_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] } }
-  named_scope :active, { :conditions => "#{Project.table_name}.status = #{STATUS_ACTIVE}"}
-  named_scope :status, lambda {|arg| arg.blank? ? {} : {:conditions => {:status => arg.to_i}} }
-  named_scope :all_public, { :conditions => { :is_public => true } }
-  named_scope :visible, lambda {|*args| {:conditions => Project.visible_condition(args.shift || User.current, *args) }}
-  named_scope :allowed_to, lambda {|*args| 
+  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 :status, lambda {|arg| arg.blank? ? {} : {:conditions => {:status => arg.to_i}} }
+  scope :all_public, { :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
     permission = nil
     if args.first.is_a?(Symbol)
@@ -98,7 +98,7 @@ class Project < ActiveRecord::Base
     end
     { :conditions => Project.allowed_to_condition(user, permission, *args) }
   }
-  named_scope :like, lambda {|arg|
+  scope :like, lambda {|arg|
     if arg.blank?
       {}
     else
index 4e72ae5c7c5695febed068bf82cccd026abc6f22..e2e1326e231e6f0da07d73c0c598249626adcf14 100644 (file)
@@ -153,7 +153,7 @@ class Query < ActiveRecord::Base
   ]
   cattr_reader :available_columns
 
-  named_scope :visible, lambda {|*args|
+  scope :visible, lambda {|*args|
     user = args.shift || User.current
     base = Project.allowed_to_condition(user, :view_issues, *args)
     user_id = user.logged? ? user.id : 0
index 06822fdbaf29a95f224e66014ffc3189f3244073..6778f6f69685cebcd8658084b959ad200008de88 100644 (file)
@@ -26,9 +26,9 @@ class Role < ActiveRecord::Base
     ['own', :label_issues_visibility_own]
   ]
 
-  named_scope :sorted, {:order => 'builtin, position'}
-  named_scope :givable, { :conditions => "builtin = 0", :order => 'position' }
-  named_scope :builtin, lambda { |*args|
+  scope :sorted, {:order => 'builtin, position'}
+  scope :givable, { :conditions => "builtin = 0", :order => 'position' }
+  scope :builtin, lambda { |*args|
     compare = 'not' if args.first == true
     { :conditions => "#{compare} builtin = 0" }
   }
index 6dbf78413a145b8988cc1b743c74779264d4aefe..e6668281f109d81225d52d91faf7631e7b2846b0 100644 (file)
@@ -42,19 +42,19 @@ class TimeEntry < ActiveRecord::Base
   before_validation :set_project_if_nil
   validate :validate_time_entry
 
-  named_scope :visible, lambda {|*args| {
+  scope :visible, lambda {|*args| {
     :include => :project,
     :conditions => Project.allowed_to_condition(args.shift || User.current, :view_time_entries, *args)
   }}
-  named_scope :on_issue, lambda {|issue| {
+  scope :on_issue, lambda {|issue| {
     :include => :issue,
     :conditions => "#{Issue.table_name}.root_id = #{issue.root_id} AND #{Issue.table_name}.lft >= #{issue.lft} AND #{Issue.table_name}.rgt <= #{issue.rgt}"
   }}
-  named_scope :on_project, lambda {|project, include_subprojects| {
+  scope :on_project, lambda {|project, include_subprojects| {
     :include => :project,
     :conditions => project.project_condition(include_subprojects)
   }}
-  named_scope :spent_between, lambda {|from, to|
+  scope :spent_between, lambda {|from, to|
     if from && to
      {:conditions => ["#{TimeEntry.table_name}.spent_on BETWEEN ? AND ?", from, to]}
     elsif from
index 32eea23093e8ddf72d31a2c815f0755ba920301d..c4d4f028aefbf414691d235c24d20b3348862312 100644 (file)
@@ -32,7 +32,7 @@ class Tracker < ActiveRecord::Base
   validates_uniqueness_of :name
   validates_length_of :name, :maximum => 30
 
-  named_scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}}
+  scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}}
 
   def to_s; name end
 
index b11d918075e05b4b215c6da66bba0772e8e4888d..8b2b61b7a5072e296e893593a602fa5b83deec96 100644 (file)
@@ -53,9 +53,9 @@ class User < Principal
   belongs_to :auth_source
 
   # Active non-anonymous users scope
-  named_scope :active, :conditions => "#{User.table_name}.status = #{STATUS_ACTIVE}"
-  named_scope :logged, :conditions => "#{User.table_name}.status <> #{STATUS_ANONYMOUS}"
-  named_scope :status, lambda {|arg| arg.blank? ? {} : {:conditions => {:status => arg.to_i}} }
+  scope :active, :conditions => "#{User.table_name}.status = #{STATUS_ACTIVE}"
+  scope :logged, :conditions => "#{User.table_name}.status <> #{STATUS_ANONYMOUS}"
+  scope :status, lambda {|arg| arg.blank? ? {} : {:conditions => {:status => arg.to_i}} }
 
   acts_as_customizable
 
@@ -84,11 +84,11 @@ class User < Principal
   before_save   :update_hashed_password
   before_destroy :remove_references_before_destroy
 
-  named_scope :in_group, lambda {|group|
+  scope :in_group, lambda {|group|
     group_id = group.is_a?(Group) ? group.id : group.to_i
     { :conditions => ["#{User.table_name}.id IN (SELECT gu.user_id FROM #{table_name_prefix}groups_users#{table_name_suffix} gu WHERE gu.group_id = ?)", group_id] }
   }
-  named_scope :not_in_group, lambda {|group|
+  scope :not_in_group, lambda {|group|
     group_id = group.is_a?(Group) ? group.id : group.to_i
     { :conditions => ["#{User.table_name}.id NOT IN (SELECT gu.user_id FROM #{table_name_prefix}groups_users#{table_name_suffix} gu WHERE gu.group_id = ?)", group_id] }
   }
index 24be5df022bf494adff045ad2c0ad07ba722c8d7..fb97fa076c71d5f6e6c303537e0821557188deb7 100644 (file)
@@ -34,9 +34,9 @@ class Version < ActiveRecord::Base
   validates_inclusion_of :status, :in => VERSION_STATUSES
   validates_inclusion_of :sharing, :in => VERSION_SHARINGS
 
-  named_scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}}
-  named_scope :open, :conditions => {:status => 'open'}
-  named_scope :visible, lambda {|*args| { :include => :project,
+  scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}}
+  scope :open, :conditions => {:status => 'open'}
+  scope :visible, lambda {|*args| { :include => :project,
                                           :conditions => Project.allowed_to_condition(args.first || User.current, :view_issues) } }
 
   safe_attributes 'name', 
index 6088e48ca9f96fbc4f7d025bd45a335529b6e401..5ca0583c2f4f91d11000e00badc80f06f79fa64d 100644 (file)
@@ -49,7 +49,7 @@ class WikiPage < ActiveRecord::Base
   before_save    :handle_redirects
 
   # eager load information about last updates, without loading text
-  named_scope :with_updated_on, {
+  scope :with_updated_on, {
     :select => "#{WikiPage.table_name}.*, #{WikiContent.table_name}.updated_on",
     :joins => "LEFT JOIN #{WikiContent.table_name} ON #{WikiContent.table_name}.page_id = #{WikiPage.table_name}.id"
   }