Class: ConfigurationItemType

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/configuration_item_type.rb

Instance Method Summary collapse

Instance Method Details

#add_configuration_option(option) ⇒ Object Also known as: add_option



48
49
50
51
52
53
54
55
# File 'app/models/configuration_item_type.rb', line 48

def add_configuration_option(option)
  self.clear_options if self.allow_user_defined_options?
  
  existing_option = self.configuration_options.where(:id => option.id).first
  if existing_option.nil?
    self.options << option
  end
end

#add_default_configuration_option(option) ⇒ Object Also known as: add_default_option



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/models/configuration_item_type.rb', line 25

def add_default_configuration_option(option)
  self.clear_options if self.allow_user_defined_options?
  
  #if this is not multi_optional clear out any default options set
  unless self.is_multi_optional?
    ConfigurationItemTypeConfigurationOption.where('configuration_item_type_id = ?', self.id).each do |configuration_item_type_configuration_option|
      configuration_item_type_configuration_option.is_default = false
    configuration_item_type_configuration_option.save
    end
  end

  existing_option = self.configuration_options.where(:id => option.id).first
  if existing_option.nil?
    ConfigurationItemTypeConfigurationOption.create(:configuration_item_type => self, :configuration_option => option, :is_default => true)
  else
    configuration_item_type_configuration_option = ConfigurationItemTypeConfigurationOption.where('configuration_option_id = ? and configuration_item_type_id = ?', existing_option.id, self.id).first
    configuration_item_type_configuration_option.is_default = true
    configuration_item_type_configuration_option.save
  end
end

#allow_user_defined_options?Boolean

Returns:

  • (Boolean)


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

def allow_user_defined_options?
  self.allow_user_defined_options
end

#categoryObject



19
20
21
# File 'app/models/configuration_item_type.rb', line 19

def category
  self.category_classification.category unless self.category_classification.nil?
end

#clear_optionsObject



82
83
84
85
86
# File 'app/models/configuration_item_type.rb', line 82

def clear_options
  self.options.each{|option|option.destroy} if self.allow_user_defined_options?
  self.options.destroy_all
  self.save
end

#find_configuration_option(internal_identifier, type = :internal_identifier) ⇒ Object



76
77
78
79
80
# File 'app/models/configuration_item_type.rb', line 76

def find_configuration_option(internal_identifier, type=:internal_identifier)
  option = self.options.where("#{type.to_s} = ?", internal_identifier).first
  raise "Option #{internal_identifier} does not exist for configuration item type #{self.description}" if option.nil?
  option
end

#is_multi_optional?Boolean

Returns:

  • (Boolean)


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

def is_multi_optional?
  self.is_multi_optional
end

#remove_configuration_option(option) ⇒ Object Also known as: remove_option



59
60
61
62
63
64
# File 'app/models/configuration_item_type.rb', line 59

def remove_configuration_option(option)
  existing_option = self.configuration_options.where(:id => option.id).first
  unless existing_option.nil?
    self.configuration_options.delete(option)
  end
end

#to_js_hashObject



88
89
90
91
92
93
94
95
96
97
# File 'app/models/configuration_item_type.rb', line 88

def to_js_hash
  {:id => self.id,
    :description => self.description,
    :internalIdentifier => self.internal_identifier,
    :configurationOptions => configuration_options.collect(&:to_js_hash),
    :defaultOptions => self.options.default.collect(&:to_js_hash),
    :isMultiOptional => self.is_multi_optional,
    :allowUserDefinedOptions => self.allow_user_defined_options
  }
end