Class: Taxonomy

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

Direct Known Subclasses

Location, Organization

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.all_import_missing_idsObject


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

def self.all_import_missing_ids
  all.each do |taxonomy|
    taxonomy.import_missing_ids
  end
end

.all_mismatchedsObject


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

def self.all_mismatcheds
  includes(:hosts).map { |taxonomy| taxonomy.mismatches }
end

.as_taxonomy(org, location) ⇒ Object


52
53
54
55
56
57
58
# File 'app/models/taxonomy.rb', line 52

def self.as_taxonomy org, location
  Organization.as_org org do
    Location.as_location location do
      yield if block_given?
    end
  end
end

.enabled?(taxonomy) ⇒ Boolean


60
61
62
63
64
65
66
67
68
69
# File 'app/models/taxonomy.rb', line 60

def self.enabled?(taxonomy)
  case taxonomy
    when :organization
      SETTINGS[:organizations_enabled]
    when :location
      SETTINGS[:locations_enabled]
    else
      raise ArgumentError, "unknown taxonomy #{taxonomy}"
  end
end

.ignore?(taxable_type) ⇒ Boolean


71
72
73
74
75
76
# File 'app/models/taxonomy.rb', line 71

def self.ignore?(taxable_type)
  Array.wrap(self.current).each{ |current|
    return true if current.ignore?(taxable_type)
  }
  false
end

.locations_enabledObject


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

def self.locations_enabled
  enabled?(:location)
end

.no_taxonomy_scopeObject


46
47
48
49
50
# File 'app/models/taxonomy.rb', line 46

def self.no_taxonomy_scope
  as_taxonomy nil, nil do
    yield if block_given?
  end
end

.organizations_enabledObject


42
43
44
# File 'app/models/taxonomy.rb', line 42

def self.organizations_enabled
  enabled?(:organization)
end

Instance Method Details

#dupObject


96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'app/models/taxonomy.rb', line 96

def dup
  new = super
  new.name = ""
  new.users             = users
  new.smart_proxies     = smart_proxies
  new.subnets           = subnets
  new.compute_resources = compute_resources
  new.media             = media
  new.domains           = domains
  new.media             = media
  new.hostgroups        = hostgroups
  new
end

#ignore?(taxable_type) ⇒ Boolean


78
79
80
81
82
83
84
# File 'app/models/taxonomy.rb', line 78

def ignore?(taxable_type)
  if ignore_types.empty?
    false
  else
    ignore_types.include?(taxable_type.classify)
  end
end

#to_labelObject


34
35
36
# File 'app/models/taxonomy.rb', line 34

def to_label
  name
end

#to_paramObject


30
31
32
# File 'app/models/taxonomy.rb', line 30

def to_param
  "#{id.to_s.parameterize}"
end