Class: DiscoveryRule

Inherits:
ApplicationRecord
  • Object
show all
Extended by:
FriendlyId
Includes:
Authorizable, Parameterizable::ByIdName, Taxonomix
Defined in:
app/models/discovery_rule.rb

Constant Summary collapse

STEP =
100

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.suggest_priority(organization = Organization.current) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'app/models/discovery_rule.rb', line 43

def self.suggest_priority(organization = Organization.current)
  discovery_rules = DiscoveryRule.unscoped
  return (discovery_rules.maximum(:priority).to_i + STEP) if organization.nil?
  discovery_rule_ids = TaxableTaxonomy.where(
    taxable_type: 'DiscoveryRule',
    taxonomy_id: organization.id).pluck(:taxable_id)
  discovery_rules = discovery_rules.where(id: discovery_rule_ids)
  discovery_rules.maximum(:priority).to_i + STEP
end

Instance Method Details

#default_int_attributesObject



38
39
40
41
# File 'app/models/discovery_rule.rb', line 38

def default_int_attributes
 self.max_count ||= 0
 self.priority  ||= 0
end

#enforce_taxonomyObject



53
54
55
56
57
58
59
60
61
62
63
# File 'app/models/discovery_rule.rb', line 53

def enforce_taxonomy
  return if hostgroup.nil?
  unless (ms = hostgroup.organizations - organizations).empty?
    names = ms.collect(&:name).to_sentence
    errors.add(:base, n_("Host group organization %s must also be associated to the discovery rule", "Host group organizations %s must also be associated to the discovery rule", ms.size) % names)
  end
  unless (ms = hostgroup.locations - locations).empty?
    names = ms.collect(&:name).to_sentence
    errors.add(:base, n_("Host group location %s must also be associated to the discovery rule", "Host group locations %s must also be associated to the discovery rule", ms.size) % names)
  end
end