Class: Enumeration
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Enumeration
- Defined in:
- app/models/enumeration.rb
Overview
redMine - project management software Copyright (C) 2006 Jean-Philippe Lang
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Constant Summary
- OPTIONS =
Single table inheritance would be an option
{ "IPRI" => {:label => :enumeration_issue_priorities, :model => Issue, :foreign_key => :priority_id, :scope => :priorities}, "DCAT" => {:label => :enumeration_doc_categories, :model => Document, :foreign_key => :category_id, :scope => :document_categories}, "ACTI" => {:label => :enumeration_activities, :model => TimeEntry, :foreign_key => :activity_id, :scope => :activities} }.freeze
Instance Method Summary (collapse)
- - (Object) <=>(enumeration)
- - (Object) before_save
-
- (Object) destroy(reassign_to = nil)
Destroy the enumeration If a enumeration is specified, objects are reassigned.
- - (Object) destroy_without_reassign
- - (Boolean) in_use?
- - (Object) objects_count
- - (Object) option_name
- - (Object) to_s
Instance Method Details
- (Object) <=>(enumeration)
83 84 85 |
# File 'app/models/enumeration.rb', line 83 def <=>(enumeration) position <=> enumeration.position end |
- (Object) before_save
58 59 60 61 62 |
# File 'app/models/enumeration.rb', line 58 def before_save if is_default? && is_default_changed? Enumeration.update_all("is_default = #{connection.quoted_false}", {:opt => opt}) end end |
- (Object) destroy(reassign_to = nil)
Destroy the enumeration If a enumeration is specified, objects are reassigned
76 77 78 79 80 81 |
# File 'app/models/enumeration.rb', line 76 def destroy(reassign_to = nil) if reassign_to && reassign_to.is_a?(Enumeration) OPTIONS[self.opt][:model].update_all("#{OPTIONS[self.opt][:foreign_key]} = #{reassign_to.id}", "#{OPTIONS[self.opt][:foreign_key]} = #{id}") end destroy_without_reassign end |
- (Object) destroy_without_reassign
72 |
# File 'app/models/enumeration.rb', line 72 alias :destroy_without_reassign :destroy |
- (Boolean) in_use?
68 69 70 |
# File 'app/models/enumeration.rb', line 68 def in_use? self.objects_count != 0 end |
- (Object) objects_count
64 65 66 |
# File 'app/models/enumeration.rb', line 64 def objects_count OPTIONS[self.opt][:model].count(:conditions => "#{OPTIONS[self.opt][:foreign_key]} = #{id}") end |
- (Object) option_name
54 55 56 |
# File 'app/models/enumeration.rb', line 54 def option_name OPTIONS[self.opt][:label] end |
- (Object) to_s
87 |
# File 'app/models/enumeration.rb', line 87 def to_s; name end |