Class: Grafana::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/grafana/validator.rb

Constant Summary collapse

Error =
Class.new(StandardError)
UNSUPPORTED_GRAFANA_GLOBAL_VARS =
%w(
  $__interval_ms
  $__timeFilter
  $__name
  $timeFilter
  $interval
).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(grafana_dashboard, datasource, panel, query_params) ⇒ Validator

Returns a new instance of Validator.


20
21
22
23
24
25
# File 'lib/grafana/validator.rb', line 20

def initialize(grafana_dashboard, datasource, panel, query_params)
  @grafana_dashboard = grafana_dashboard
  @datasource = datasource
  @panel = panel
  @query_params = query_params
end

Instance Attribute Details

#datasourceObject (readonly)

Returns the value of attribute datasource.


10
11
12
# File 'lib/grafana/validator.rb', line 10

def datasource
  @datasource
end

#grafana_dashboardObject (readonly)

Returns the value of attribute grafana_dashboard.


10
11
12
# File 'lib/grafana/validator.rb', line 10

def grafana_dashboard
  @grafana_dashboard
end

#panelObject (readonly)

Returns the value of attribute panel.


10
11
12
# File 'lib/grafana/validator.rb', line 10

def panel
  @panel
end

#query_paramsObject (readonly)

Returns the value of attribute query_params.


10
11
12
# File 'lib/grafana/validator.rb', line 10

def query_params
  @query_params
end

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)

35
36
37
38
39
40
41
# File 'lib/grafana/validator.rb', line 35

def valid?
  validate!

  true
rescue ::Grafana::Validator::Error
  false
end

#validate!Object


27
28
29
30
31
32
33
# File 'lib/grafana/validator.rb', line 27

def validate!
  validate_query_params!
  validate_panel_type!
  validate_variable_definitions!
  validate_global_variables!
  validate_datasource! if datasource
end