Skip to content

Commit

Permalink
Solara
Browse files Browse the repository at this point in the history
  • Loading branch information
IdeaS0ft committed Sep 14, 2024
1 parent 9529906 commit ecf9498
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions solara/lib/core/brands/brands_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -42,25 +47,18 @@ 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

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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ecf9498

Please sign in to comment.