Class: ForemanStatistics::FactTrend

Inherits:
Trend
  • Object
show all
Defined in:
app/models/foreman_statistics/fact_trend.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Trend

build_trend, humanize_class_name, title_name, #to_param

Class Method Details

.create_values(fact_name_id) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'app/models/foreman_statistics/fact_trend.rb', line 23

def self.create_values(fact_name_id)
  FactValue.select('fact_name_id, value').group(:fact_name_id, :value).where(:fact_name_id => fact_name_id).includes(:fact_name).map do |fact|
    create(:trendable_type => 'FactName',
           :trendable_id => fact.fact_name.id,
           :fact_name => fact.fact_name.name,
           :fact_value => fact.value,
           :name => fact.value)
  end
end

.model_nameObject



43
44
45
# File 'app/models/foreman_statistics/fact_trend.rb', line 43

def self.model_name
  Trend.model_name
end

Instance Method Details

#create_valuesObject



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

def create_values
  self.class.create_values(trendable_id)
end

#destroy_valuesObject



33
34
35
36
# File 'app/models/foreman_statistics/fact_trend.rb', line 33

def destroy_values
  ids = FactTrend.where(:trendable_id => trendable_id, :trendable_type => trendable_type).pluck(:id)
  super(ids)
end

#find_hostsObject



47
48
49
# File 'app/models/foreman_statistics/fact_trend.rb', line 47

def find_hosts
  Host.joins(:fact_values).where(:fact_values => { :value => fact_value }).order(:name)
end

#to_labelObject



7
8
9
# File 'app/models/foreman_statistics/fact_trend.rb', line 7

def to_label
  name.presence || fact_value || fact_name
end

#type_nameObject



11
12
13
14
15
16
17
# File 'app/models/foreman_statistics/fact_trend.rb', line 11

def type_name
  if fact_value.blank?
    name.presence || fact_name
  else
    fact_name
  end
end

#valuesObject



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

def values
  return FactTrend.where(:id => self) if fact_value
  FactTrend.has_value.where(:trendable_type => trendable_type, :trendable_id => trendable_id)
end