Sha256: 926ca6e92fd6a66fe6d95a78a6b2de33451685c8244622f69329001895e3ef9c

Contents?: true

Size: 688 Bytes

Versions: 8

Compression:

Stored size: 688 Bytes

Contents

module Blazer
  class Query < ActiveRecord::Base
    belongs_to :creator, Blazer::BELONGS_TO_OPTIONAL.merge(class_name: Blazer.user_class.to_s) if Blazer.user_class
    has_many :checks, dependent: :destroy
    has_many :dashboard_queries, dependent: :destroy
    has_many :dashboards, through: :dashboard_queries
    has_many :audits

    validates :statement, presence: true

    scope :named, -> { where("name <> ''") }

    def to_param
      [id, name].compact.join("-").gsub("'", "").parameterize
    end

    def friendly_name
      name.to_s.gsub(/\[.+\]/, "").strip
    end

    def editable?(user)
      (name.present? && name.first != "*") || user == creator
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
blazer-1.6.1 app/models/blazer/query.rb
blazer-1.6.0 app/models/blazer/query.rb
blazer-1.5.1 app/models/blazer/query.rb
blazer-1.5.0 app/models/blazer/query.rb
blazer-1.4.0 app/models/blazer/query.rb
blazer-1.3.5 app/models/blazer/query.rb
blazer-1.3.4 app/models/blazer/query.rb
blazer-1.3.3 app/models/blazer/query.rb