module ForemanSalt::Concerns::HostgroupExtensions

def all_salt_modules

def all_salt_modules
  ForemanSalt::SaltModule.in_environment(salt_environment).where(:id => salt_module_ids + inherited_salt_module_ids)
end

def inherited_salt_environment_id

def inherited_salt_environment_id
  if ancestry.present?
    self[:salt_environment_id] || self.class.sort_by_ancestry(ancestors.where('salt_environment_id is not NULL')).last.try(:salt_environment_id)
  else
    salt_environment_id
  end
end

def inherited_salt_module_ids

def inherited_salt_module_ids
  ancestors.map(&:salt_module_ids).flatten.uniq
end

def inherited_salt_modules

def inherited_salt_modules
  ForemanSalt::SaltModule.where(:id => inherited_salt_module_ids)
end

def inherited_salt_proxy_id

def inherited_salt_proxy_id
  if ancestry.present?
    self[:salt_proxy_id] || self.class.sort_by_ancestry(ancestors.where('salt_proxy_id is not NULL')).last.try(:salt_proxy_id)
  else
    salt_proxy_id
  end
end

def salt_environment

def salt_environment
  return super unless ancestry.present?
  ForemanSalt::SaltEnvironment.find_by_id(inherited_salt_environment_id)
end

def salt_master

def salt_master
  salt_proxy.to_s
end

def salt_proxy

def salt_proxy
  return super unless ancestry.present?
  SmartProxy.find_by_id(inherited_salt_proxy_id)
end