class StreamdeckProf::Profile

Attributes

manifest[R]
profile_dir[R]

Public Class Methods

new(profile_dir) click to toggle source
# File lib/streamdeck_prof/profile.rb, line 12
def initialize(profile_dir)
  @profile_dir = profile_dir
  @manifest = JSON.parse(File.read(manifest_path))
end

Public Instance Methods

actions() click to toggle source
# File lib/streamdeck_prof/profile.rb, line 37
def actions
  @actions ||= StreamdeckProf::ActionList.new.tap do |actions|
    actions_hash = actions.to_h
    manifest["Actions"].each do |key, value|
      actions_hash[key] = make_action(key, value)
    end
  end
end
actions=(actions) click to toggle source
# File lib/streamdeck_prof/profile.rb, line 46
def actions=(actions)
  @actions = actions || StreamdeckProf::ActionList.new
end
app_identifier() click to toggle source
# File lib/streamdeck_prof/profile.rb, line 29
def app_identifier
  manifest["AppIdentifier"]
end
app_identifier=(app_identifier) click to toggle source
# File lib/streamdeck_prof/profile.rb, line 33
def app_identifier=(app_identifier)
  manifest["AppIdentifier"] = app_identifier
end
name() click to toggle source
# File lib/streamdeck_prof/profile.rb, line 21
def name
  manifest["Name"]
end
name=(name) click to toggle source
# File lib/streamdeck_prof/profile.rb, line 25
def name=(name)
  manifest["Name"] = name
end
save() click to toggle source
# File lib/streamdeck_prof/profile.rb, line 50
def save
  sync_manifest
  @actions&.to_h&.each { |position_key, action| action.save(action_storage_path(position_key)) }
  File.write(manifest_path, JSON.dump(manifest))
end
uuid() click to toggle source
# File lib/streamdeck_prof/profile.rb, line 17
def uuid
  File.basename(profile_dir, ".sdProfile")
end

Private Instance Methods

action_storage_path(position_key) click to toggle source
# File lib/streamdeck_prof/profile.rb, line 78
def action_storage_path(position_key)
  File.join(profile_dir, position_key)
end
make_action(position_key, config) click to toggle source
# File lib/streamdeck_prof/profile.rb, line 66
def make_action(position_key, config)
  StreamdeckProf::Action.new(config).tap do |action|
    storage_path = action_storage_path(position_key)
    Dir.glob(File.join(storage_path, "**/*"))
       .reject { |path| File.directory?(path) }
       .each do |path|
         file_key = relative_path(storage_path, path)
         action.files[file_key] = StreamdeckProf::LazyFile.new(path)
       end
  end
end
manifest_path() click to toggle source
# File lib/streamdeck_prof/profile.rb, line 62
def manifest_path
  File.join(profile_dir, "manifest.json")
end
relative_path(from_path, to_path) click to toggle source
# File lib/streamdeck_prof/profile.rb, line 82
def relative_path(from_path, to_path)
  Pathname.new(to_path).relative_path_from(Pathname.new(from_path)).to_s
end
sync_manifest() click to toggle source
# File lib/streamdeck_prof/profile.rb, line 58
def sync_manifest
  manifest["Actions"] = actions.to_h.transform_values(&:to_h) unless @actions.nil?
end