Skip to content

Commit

Permalink
Improvements to script model after review
Browse files Browse the repository at this point in the history
  • Loading branch information
abujeda committed Sep 1, 2023
1 parent 8b3bc71 commit 48726e9
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions apps/dashboard/app/models/script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ def scripts_dir(project_dir)
end
end

def creation_marker_path(script_dir)
File.join(script_dir, ".created.json")
end

def find(id, project_dir)
script_path = Script.script_path(project_dir, id)
file = script_form_file(script_path)
Expand Down Expand Up @@ -46,7 +42,7 @@ def from_yaml(file, project_dir)
nil
end

def next_id(project_dir)
def next_id
SecureRandom.alphanumeric(8).downcase
end
end
Expand Down Expand Up @@ -131,12 +127,11 @@ def []=(_id, value)
end

def save
@id = Script.next_id(project_dir) if @id.nil?
@id = Script.next_id if @id.nil?
@created_at = Time.now.to_i if @created_at.nil?
script_path = Script.script_path(project_dir, id)
script_path.mkpath unless script_path.exist?
File.write(Script.script_form_file(script_path), to_yaml)
add_creation_marker(script_path)

true
rescue StandardError => e
Expand Down Expand Up @@ -256,11 +251,6 @@ def cache_file_exists?
cache_file_path.exist?
end

def add_creation_marker(script_dir)
creation_marker = Pathname.new(Script.creation_marker_path(script_dir))
File.write(creation_marker, { }.to_json) unless creation_marker.exist?
end

def cached_values
@cached_values ||= begin
cache_file_path = OodAppkit.dataroot.join(Script.scripts_dir("#{project_dir}"), "#{id}_opts.json")
Expand Down

0 comments on commit 48726e9

Please sign in to comment.