Sha256: aa8e35c1e75dc1d8fb4da775992c9d3aaa8fd9a83e98b42ab0085c3e974044ed

Contents?: true

Size: 1.06 KB

Versions: 9

Compression:

Stored size: 1.06 KB

Contents

module Blazer
  class Query < Record
    belongs_to :creator, optional: true, 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("blazer_queries.name <> ''") }

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

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

    def viewable?(user)
      if Blazer.query_viewable
        Blazer.query_viewable.call(self, user)
      else
        true
      end
    end

    def editable?(user)
      editable = !persisted? || (name.present? && name.first != "*" && name.first != "#") || user == try(:creator)
      editable &&= viewable?(user)
      editable &&= Blazer.query_editable.call(self, user) if Blazer.query_editable
      editable
    end

    def variables
      Blazer.extract_vars(statement)
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
blazer-2.2.8 app/models/blazer/query.rb
blazer-2.2.7 app/models/blazer/query.rb
blazer-2.2.6 app/models/blazer/query.rb
blazer-2.2.5 app/models/blazer/query.rb
blazer-2.2.4 app/models/blazer/query.rb
blazer-2.2.3 app/models/blazer/query.rb
blazer-2.2.2 app/models/blazer/query.rb
blazer-2.2.1 app/models/blazer/query.rb
blazer-2.2.0 app/models/blazer/query.rb