Class: Kennel::Models::Dash

Inherits:
Base
  • Object
show all
Includes:
OptionalValidations, TemplateVariables
Defined in:
lib/kennel/models/dash.rb

Constant Summary collapse

API_LIST_INCOMPLETE =
true
SUPPORTED_GRAPH_OPTIONS =
[:events, :markers, :precision].freeze
READONLY_ATTRIBUTES =
(Base::READONLY_ATTRIBUTES + [:resource, :created_by, :read_only]).freeze
DEFINITION_DEFAULTS =
{ autoscale: true }.freeze
DASH_DEFAULTS =
{ template_variables: [] }.freeze

Constants inherited from Base

Base::LOCK, Base::REQUEST_DEFAULTS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from OptionalValidations

all_keys, included

Methods included from TemplateVariables

included

Methods inherited from Base

defaults, #diff, inherited, #kennel_id, #name, #resolve_linked_tracking_ids, settings, #to_json, #tracking_id, validate_setting_exists

Methods included from SubclassTracking

#recursive_subclasses, #subclasses

Constructor Details

#initialize(project, *args) ⇒ Dash

Returns a new instance of Dash.



26
27
28
29
# File 'lib/kennel/models/dash.rb', line 26

def initialize(project, *args)
  @project = project
  super(*args)
end

Instance Attribute Details

#projectObject (readonly)

Returns the value of attribute project.



24
25
26
# File 'lib/kennel/models/dash.rb', line 24

def project
  @project
end

Class Method Details

.api_resourceObject



31
32
33
# File 'lib/kennel/models/dash.rb', line 31

def self.api_resource
  "dash"
end

.normalize(expected, actual) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/kennel/models/dash.rb', line 50

def self.normalize(expected, actual)
  super

  actual[:template_variables] ||= [] # is nil when it never had template variables
  ignore_default expected, actual, DASH_DEFAULTS

  (actual[:graphs] || {}).each do |g|
    g[:definition].delete(:status)
  end
  ignore_request_defaults expected, actual, :graphs, :definition

  (actual[:graphs] || []).each_with_index do |a_g, i|
    a_d = a_g[:definition] || {}
    e_d = expected.dig(:graphs, i, :definition) || {}
    ignore_default e_d, a_d, DEFINITION_DEFAULTS
  end
end

Instance Method Details

#as_jsonObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/kennel/models/dash.rb', line 35

def as_json
  return @json if @json
  @json = {
    id: id,
    title: "#{title}#{LOCK}",
    description: description,
    template_variables: render_template_variables,
    graphs: render_graphs
  }

  validate_json(@json) if validate

  @json
end

#url(id) ⇒ Object



68
69
70
# File 'lib/kennel/models/dash.rb', line 68

def url(id)
  Utils.path_to_url "/dash/#{id}"
end