Class: ConfigurationItemType
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- ConfigurationItemType
- Defined in:
- app/models/configuration_item_type.rb
Instance Method Summary collapse
- #add_configuration_option(option) ⇒ Object (also: #add_option)
- #add_default_configuration_option(option) ⇒ Object (also: #add_default_option)
- #allow_user_defined_options? ⇒ Boolean
- #category ⇒ Object
- #clear_options ⇒ Object
- #find_configuration_option(internal_identifier, type = :internal_identifier) ⇒ Object
- #is_multi_optional? ⇒ Boolean
- #remove_configuration_option(option) ⇒ Object (also: #remove_option)
- #to_js_hash ⇒ Object
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. if self. existing_option = self..where(:id => option.id).first if existing_option.nil? self. << 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. if self. #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..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
72 73 74 |
# File 'app/models/configuration_item_type.rb', line 72 def self. end |
#category ⇒ Object
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_options ⇒ Object
82 83 84 85 86 |
# File 'app/models/configuration_item_type.rb', line 82 def self..each{|option|option.destroy} if self. self..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..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
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..where(:id => option.id).first unless existing_option.nil? self..delete(option) end end |
#to_js_hash ⇒ Object
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 => .collect(&:to_js_hash), :defaultOptions => self..default.collect(&:to_js_hash), :isMultiOptional => self.is_multi_optional, :allowUserDefinedOptions => self. } end |