From ecf9498469ec9d864d16d0eb6ed146342dfae02c Mon Sep 17 00:00:00 2001 From: Shaban Kamel Date: Sun, 15 Sep 2024 00:40:16 +0300 Subject: [PATCH] Solara --- solara/lib/core/brands/brands_manager.rb | 31 +++++++++--------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/solara/lib/core/brands/brands_manager.rb b/solara/lib/core/brands/brands_manager.rb index 26acfb5..03fa7d7 100644 --- a/solara/lib/core/brands/brands_manager.rb +++ b/solara/lib/core/brands/brands_manager.rb @@ -5,6 +5,11 @@ class BrandsManager include Singleton + # Class method to access the singleton instance + def self.instance + @instance ||= new + end + def initialize brands_list_path = FilePath.brands_list @brands_list = JSON.parse(File.read(brands_list_path)) @@ -42,11 +47,11 @@ def add_brand(brand_name, brand_key) existing_brand = brand_data(brand_key) if existing_brand update_brand(brands_list.index(existing_brand), brand) - Solara.logger.debug("#{brand_name} Brand updated in the list.") + Solara.logger.debug("#{brand_name} Brand updated in the brands list.") else brands_list.push(brand) save_brands_list - Solara.logger.debug("#{brand_name} added to the list.") + Solara.logger.debug("#{brand_name} added to the brands list.") end end @@ -54,13 +59,6 @@ def current_brand JSON.parse(File.read(FilePath.current_brand)) end - def current_brand_content_changed(brand_key) - unless is_current_brand(brand_key) - return false - end - current_brand['content_changed'] == true - end - def set_current_brand_content_changed(brand_key, changed) unless is_current_brand(brand_key) return false @@ -78,17 +76,17 @@ def is_current_brand(brand_key) def save_current_brand(brand_key) brand = brand_data(brand_key) - save_current_brand_date(brand) + save_current_brand_data(brand) Solara.logger.debug("#{brand_key} saved as current brand.") end - def save_current_brand_date(brand_data) - current_brand = FilePath.current_brand + def save_current_brand_data(brand_data) + path = FilePath.current_brand # Create the file if it doesn't exist - FileUtils.touch(current_brand) unless File.exist?(current_brand) + FileUtils.touch(path) unless File.exist?(path) - File.open(current_brand, 'w') do |file| + File.open(path, 'w') do |file| file.write(JSON.pretty_generate(brand_data)) end @@ -119,11 +117,6 @@ def offboard(brand_key) end end - # Class method to access the singleton instance - def self.instance - @instance ||= new - end - private def save_brands_list