Class: Enumeration
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Enumeration
- Defined in:
- app/models/enumeration.rb
Overview
redMine - project management software Copyright © 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.
Direct Known Subclasses
Class Method Summary collapse
- .default ⇒ Object
-
.get_subclasses ⇒ Object
Returns the Subclasses of Enumeration.
-
.overridding_change?(new, previous) ⇒ Boolean
Does the
new
Hash override the previous Enumeration?. -
.same_active_state?(new, previous) ⇒ Boolean
Are the new and previous fields equal?.
-
.same_custom_values?(new, previous) ⇒ Boolean
Does the
new
Hash have the same custom values as the previous Enumeration?.
Instance Method Summary collapse
- #<=>(enumeration) ⇒ Object
- #before_save ⇒ Object
-
#destroy(reassign_to = nil) ⇒ Object
Destroy the enumeration If a enumeration is specified, objects are reassigned.
- #destroy_without_reassign ⇒ Object
- #in_use? ⇒ Boolean
-
#is_override? ⇒ Boolean
Is this enumeration overiding a system level enumeration?.
-
#objects_count ⇒ Object
Overloaded on concrete classes.
-
#option_name ⇒ Object
Overloaded on concrete classes.
- #to_s ⇒ Object
Class Method Details
.default ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/models/enumeration.rb', line 36 def self.default # Creates a fake default scope so Enumeration.default will check # it's type. STI subclasses will automatically add their own # types to the finder. if self.descends_from_active_record? find(:first, :conditions => { :is_default => true, :type => 'Enumeration' }) else # STI classes are find(:first, :conditions => { :is_default => true }) end end |
.get_subclasses ⇒ Object
Returns the Subclasses of Enumeration. Each Subclass needs to be required in development mode.
Note: subclasses is protected in ActiveRecord
94 95 96 |
# File 'app/models/enumeration.rb', line 94 def self.get_subclasses @@subclasses[Enumeration] end |
.overridding_change?(new, previous) ⇒ Boolean
Does the new
Hash override the previous Enumeration?
99 100 101 102 103 104 105 |
# File 'app/models/enumeration.rb', line 99 def self.overridding_change?(new, previous) if (same_active_state?(new['active'], previous.active)) && same_custom_values?(new,previous) return false else return true end end |
.same_active_state?(new, previous) ⇒ Boolean
Are the new and previous fields equal?
119 120 121 122 |
# File 'app/models/enumeration.rb', line 119 def self.same_active_state?(new, previous) new = (new == "1" ? true : false) return new == previous end |
.same_custom_values?(new, previous) ⇒ Boolean
Does the new
Hash have the same custom values as the previous Enumeration?
108 109 110 111 112 113 114 115 116 |
# File 'app/models/enumeration.rb', line 108 def self.same_custom_values?(new, previous) previous.custom_field_values.each do |custom_value| if custom_value.value != new["custom_field_values"][custom_value.custom_field_id.to_s] return false end end return true end |
Instance Method Details
#<=>(enumeration) ⇒ Object
84 85 86 |
# File 'app/models/enumeration.rb', line 84 def <=>(enumeration) position <=> enumeration.position end |
#before_save ⇒ Object
53 54 55 56 57 |
# File 'app/models/enumeration.rb', line 53 def before_save if is_default? && is_default_changed? Enumeration.update_all("is_default = #{connection.quoted_false}", {:type => type}) end end |
#destroy(reassign_to = nil) ⇒ Object
Destroy the enumeration If a enumeration is specified, objects are reassigned
77 78 79 80 81 82 |
# File 'app/models/enumeration.rb', line 77 def destroy(reassign_to = nil) if reassign_to && reassign_to.is_a?(Enumeration) self.transfer_relations(reassign_to) end destroy_without_reassign end |
#destroy_without_reassign ⇒ Object
73 |
# File 'app/models/enumeration.rb', line 73 alias :destroy_without_reassign :destroy |
#in_use? ⇒ Boolean
64 65 66 |
# File 'app/models/enumeration.rb', line 64 def in_use? self.objects_count != 0 end |
#is_override? ⇒ Boolean
Is this enumeration overiding a system level enumeration?
69 70 71 |
# File 'app/models/enumeration.rb', line 69 def is_override? !self.parent.nil? end |
#objects_count ⇒ Object
Overloaded on concrete classes
60 61 62 |
# File 'app/models/enumeration.rb', line 60 def objects_count 0 end |
#option_name ⇒ Object
Overloaded on concrete classes
49 50 51 |
# File 'app/models/enumeration.rb', line 49 def option_name nil end |
#to_s ⇒ Object
88 |
# File 'app/models/enumeration.rb', line 88 def to_s; name end |