Class: Enumeration

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Redmine::SubclassFactory
Defined in:
app/models/enumeration.rb

Overview

Redmine - project management software Copyright (C) 2006-2016 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.

Since:

  • 0.4.0

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.defaultObject

Since:

  • 0.6.0



44
45
46
47
48
49
50
51
52
53
54
# File 'app/models/enumeration.rb', line 44

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?
    where(:is_default => true, :type => 'Enumeration').first
  else
    # STI classes are
    where(:is_default => true).first
  end
end

.get_subclassesObject

Returns the Subclasses of Enumeration. Each Subclass needs to be required in development mode.

Note: subclasses is protected in ActiveRecord

Since:

  • 0.9.0



102
103
104
# File 'app/models/enumeration.rb', line 102

def self.get_subclasses
  subclasses
end

.overriding_change?(new, previous) ⇒ Boolean

Does the new Hash override the previous Enumeration?

Returns:

  • (Boolean)

Since:

  • 2.6.0



107
108
109
110
111
112
113
# File 'app/models/enumeration.rb', line 107

def self.overriding_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?

Returns:

  • (Boolean)

Since:

  • 0.9.0



127
128
129
130
# File 'app/models/enumeration.rb', line 127

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?

Returns:

  • (Boolean)

Since:

  • 0.9.0



116
117
118
119
120
121
122
123
124
# File 'app/models/enumeration.rb', line 116

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

Since:

  • 0.6.0



92
93
94
# File 'app/models/enumeration.rb', line 92

def <=>(enumeration)
  position <=> enumeration.position
end

#check_defaultObject

Since:

  • 1.3.0



61
62
63
64
65
# File 'app/models/enumeration.rb', line 61

def check_default
  if is_default? && is_default_changed?
    Enumeration.where({:type => type}).update_all({:is_default => false})
  end
end

#destroy(reassign_to = nil) ⇒ Object

Destroy the enumeration If a enumeration is specified, objects are reassigned

Since:

  • 0.8.0



85
86
87
88
89
90
# File 'app/models/enumeration.rb', line 85

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_reassignObject

Since:

  • 0.8.0



81
# File 'app/models/enumeration.rb', line 81

alias :destroy_without_reassign :destroy

#in_use?Boolean

Returns:

  • (Boolean)

Since:

  • 0.8.0



72
73
74
# File 'app/models/enumeration.rb', line 72

def in_use?
  self.objects_count != 0
end

#is_override?Boolean

Is this enumeration overriding a system level enumeration?

Returns:

  • (Boolean)

Since:

  • 0.9.0



77
78
79
# File 'app/models/enumeration.rb', line 77

def is_override?
  !self.parent.nil?
end

#objects_countObject

Overloaded on concrete classes

Since:

  • 0.8.0



68
69
70
# File 'app/models/enumeration.rb', line 68

def objects_count
  0
end

#option_nameObject

Overloaded on concrete classes



57
58
59
# File 'app/models/enumeration.rb', line 57

def option_name
  nil
end

#to_sObject

Since:

  • 0.6.0



96
# File 'app/models/enumeration.rb', line 96

def to_s; name end