From 9a63b36dca254ffda5c711b50903cac673eb47ca Mon Sep 17 00:00:00 2001 From: Patricio de Villa Date: Thu, 21 Mar 2024 01:19:14 -0600 Subject: [PATCH] fix Dashboard --- Gemfile | 1 - lib/kibana/dashboard.rb | 36 +++++++++++++++++++++++++----------- lib/kibana/version.rb | 2 +- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/Gemfile b/Gemfile index f1f040e..c3229ce 100644 --- a/Gemfile +++ b/Gemfile @@ -12,7 +12,6 @@ gem 'debug', '>= 1.0.0' gem 'minitest', '~> 5.14' gem 'minitest-reporters', '~> 1.6' gem 'rake', '~> 13.1' -gem 'super_hash', '0.3.2', git: 'https://github.com/prysmex/super_hash.git' # rubocop gem 'rubocop', '~> 1.62' diff --git a/lib/kibana/dashboard.rb b/lib/kibana/dashboard.rb index bd30436..4444c48 100644 --- a/lib/kibana/dashboard.rb +++ b/lib/kibana/dashboard.rb @@ -1,11 +1,27 @@ # frozen_string_literal: true require 'securerandom' -require 'super_hash' module Kibana CLIENT_VERSION = '8.12.1' module Dashboard + + # @note This could be removed if classes inherit from ActiveSupport::HashWithIndifferentAccess + # + # Allows a hash to be initialized via .new({...}) + module HashInit + def initialize(init_value = {}) + # iterate init_value and set all values + if init_value.respond_to?(:each_pair) + init_value.each do |k, v| + self[k] = v + end + else + super + end + end + end + # PANELS_JSON_VISUALIZATION_VERSION = '8.9.1'.freeze CORE_MIGRATION_VERSION = '8.8.0' TYPE_MIGRATION_VERSION = '8.9.0' @@ -33,8 +49,7 @@ module Dashboard # } # class PanelJSON < Hash - # include SuperHash::Hasher - # instance_variable_set(:@allow_dynamic_attributes, true) + include HashInit # Distance of right side of panel to left side of dashboard # @@ -86,8 +101,7 @@ def y2 # rubocop:enable Layout/LineLength # class Dashboard < Hash - # include SuperHash::Hasher - instance_variable_set(:@allow_dynamic_attributes, true) + include HashInit DASHBOARD_MAX_WIDTH = 48 @@ -328,9 +342,9 @@ def insert_visualization_at(x:, y:, w:, h:, reference_id:, title:, panel_id: Sec # add reference to the dashboard 'references' key self['references'].push({ - id: reference_id, - name: "#{panel_id}:panel_#{panel_id}", - type: 'visualization' + 'id' => reference_id, + 'name' => "#{panel_id}:panel_#{panel_id}", + 'type' => 'visualization' }) end @@ -478,9 +492,9 @@ def add_tag(id) return false if self['references'].find { |i| i['id'] == id } self['references'].push({ - id: id.to_s, - name: "tag-#{id}", - type: 'tag' + 'id' => id.to_s, + 'name' => "tag-#{id}", + 'type' => 'tag' }) end diff --git a/lib/kibana/version.rb b/lib/kibana/version.rb index 082a9ac..d4128bf 100644 --- a/lib/kibana/version.rb +++ b/lib/kibana/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Kibana - VERSION = '0.8.6' + VERSION = '0.8.7' end