Sha256: 05521d43ffe759a04885a3a32965b1f4f464da6cea356ab5293e6b07b3bc74b4

Contents?: true

Size: 984 Bytes

Versions: 11

Compression:

Stored size: 984 Bytes

Contents

module ForemanStatistics
  class ForemanTrend < Trend
    validates :trendable_id, :uniqueness => { :scope => :trendable_type }
    validates :trendable_type, :presence => true

    def to_label
      trendable ? trendable.to_label : trendable_type
    end

    def type_name
      trendable_type
    end

    def create_values
      self.class.create_values(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
      return Host::Managed.none unless trendable
      trendable.hosts.order(:name)
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
foreman_statistics-2.1.0 app/models/foreman_statistics/foreman_trend.rb
foreman_statistics-2.0.1 app/models/foreman_statistics/foreman_trend.rb
foreman_statistics-2.0.0 app/models/foreman_statistics/foreman_trend.rb
foreman_statistics-1.2.0 app/models/foreman_statistics/foreman_trend.rb
foreman_statistics-1.1.1 app/models/foreman_statistics/foreman_trend.rb
foreman_statistics-1.1.0 app/models/foreman_statistics/foreman_trend.rb
foreman_statistics-1.0.0 app/models/foreman_statistics/foreman_trend.rb
foreman_statistics-0.1.3 app/models/foreman_statistics/foreman_trend.rb
foreman_statistics-0.1.2 app/models/foreman_statistics/foreman_trend.rb
foreman_statistics-0.1.1 app/models/foreman_statistics/foreman_trend.rb
foreman_statistics-0.1.0 app/models/foreman_statistics/foreman_trend.rb