Sha256: 74bcc4d703dcc0a01efb35532221ae15ba67c1374771c8bbb854340a12f6dab8

Contents?: true

Size: 818 Bytes

Versions: 5

Compression:

Stored size: 818 Bytes

Contents

class ForemanTrend < Trend

  validates :trendable_id, :uniqueness => {:scope => :trendable_type}

  def to_label
    trendable ? trendable.to_label : trendable_type
  end

  def type_name
    trendable_type
  end

  def create_values
    self.class.create_values(self.trendable_type)
  end

  def self.create_values(trendable_type)
    trendable_type.constantize.all.map { |t| t.trends.create(:fact_value => t.to_label)}
  end

  def destroy_values
    ids = ForemanTrend.where(:trendable_type => trendable_type).pluck(:id)
    super(ids)
  end

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

  def self.model_name
    Trend.model_name
  end

  def find_hosts
    trendable.hosts.find(:all, :order => 'name')
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
foreman_discovery-1.0.0 test/foreman_app/app/models/foreman_trend.rb
foreman_discovery-1.0.0.rc4 test/foreman_app/app/models/foreman_trend.rb
foreman_discovery-1.0.0.rc3 test/foreman_app/app/models/foreman_trend.rb
foreman_discovery-1.0.0.rc2 test/foreman_app/app/models/foreman_trend.rb
foreman_discovery-1.0.0.rc1 test/foreman_app/app/models/foreman_trend.rb