streamdeck_prof 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9363c4d74f520821730803e7d06c7d23d931c4f7d5f3ae2038738e5c91224d19
4
- data.tar.gz: b06f7c657c7c95006353b911e9e9ce434902a13ed6d8c7459fd6fc1a7b18ac06
3
+ metadata.gz: 3ace94ce151092f94e0ce3bf65778ab898bc2ebae2fe54c579cf824a7ea243e6
4
+ data.tar.gz: '039f070c7911048c2dc54c38c3423ae1af2783f59a779377d04b9026af711dba'
5
5
  SHA512:
6
- metadata.gz: 56773390486d43d82ead735ee4f87e6135a2a90dec7c757e3057e1504f3270a662229a91a4561f0c12ff038de47a51d6b533255a9a67f84af0639ee97f576750
7
- data.tar.gz: cfdf3dc483cec4eb7d3f8a6b63b015e26b3da28c2b0af95fc0c86e1ad495d85cc2a535425bc32e2740900315db982190426f446fa547c216f62fdb2edb6ce224
6
+ metadata.gz: 47470d8f67fd04a2cd0249f6c36d67bb0cb66f75c837c0511d341ddf1365a7cddf5d08e671524990d75c57397fd06fa700ac75a5e17bfad48466de536b3014a4
7
+ data.tar.gz: 2c0646770acc82e350c93a2cdb0b597259e24948e798f4be8c35208041d2fdc1a38c7d7334223f89e7ef584dcbb955b91c2976c5d35c69666a2540b679ed7cd5
@@ -1,53 +1,56 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "streamdeck_prof/file_list"
4
+
3
5
  module StreamdeckProf
4
6
  class Action
5
- attr_reader :profile, :position_x, :position_y
6
-
7
- def initialize(profile, x, y)
8
- @profile = profile
9
- @position_x = x
10
- @position_y = y
11
- end
12
-
13
- def internal_id
14
- "#{position_x},#{position_y}"
15
- end
7
+ attr_accessor :config, :files
16
8
 
17
- def manifest
18
- profile.manifest["Actions"][internal_id] ||= {}
9
+ def initialize(config)
10
+ @config = config
11
+ @files = FileList.new
19
12
  end
20
13
 
21
14
  def uuid
22
- manifest["UUID"]
15
+ config["UUID"]
23
16
  end
24
17
 
25
18
  def uuid=(uuid)
26
- manifest["UUID"] = uuid
19
+ config["UUID"] = uuid
27
20
  end
28
21
 
29
22
  def name
30
- manifest["Name"]
23
+ config["Name"]
31
24
  end
32
25
 
33
26
  def name=(name)
34
- manifest["Name"] = name
27
+ config["Name"] = name
35
28
  end
36
29
 
37
30
  def state
38
- manifest["State"]
31
+ config["State"]
39
32
  end
40
33
 
41
34
  def state=(state)
42
- manifest["State"] = state
35
+ config["State"] = state
43
36
  end
44
37
 
45
38
  def settings
46
- manifest["Settings"]
39
+ config["Settings"]
47
40
  end
48
41
 
49
42
  def settings=(settings)
50
- manifest["Settings"] = settings
43
+ config["Settings"] = settings
44
+ end
45
+
46
+ def to_hash
47
+ config
48
+ end
49
+
50
+ alias to_h to_hash
51
+
52
+ def save(storage_path)
53
+ files.save(storage_path)
51
54
  end
52
55
  end
53
56
  end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module StreamdeckProf
4
+ class ActionList
5
+ def initialize
6
+ @actions = {}
7
+ end
8
+
9
+ def [](x, y)
10
+ @actions[coordinates(x, y)]
11
+ end
12
+
13
+ def []=(x, y, value)
14
+ key = coordinates(x, y)
15
+ if value.nil?
16
+ @actions.delete(key)
17
+ else
18
+ @actions[key] = value
19
+ end
20
+ end
21
+
22
+ def to_hash
23
+ @actions
24
+ end
25
+
26
+ alias to_h to_hash
27
+
28
+ private
29
+
30
+ def initialize_copy(original)
31
+ @actions = original.to_h.dup
32
+ end
33
+
34
+ def coordinates(x, y)
35
+ "#{x},#{y}"
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module StreamdeckProf
4
+ class FileList
5
+ def initialize
6
+ @files = {}
7
+ end
8
+
9
+ def [](path)
10
+ @files[path]
11
+ end
12
+
13
+ def []=(path, file)
14
+ if file.nil?
15
+ @files.delete(path)
16
+ else
17
+ @files[path] = file
18
+ end
19
+ end
20
+
21
+ def to_hash
22
+ @files
23
+ end
24
+
25
+ alias to_h to_hash
26
+
27
+ def save(storage_path)
28
+ @files.each { |path, file| file.save(File.join(storage_path, path)) }
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "fileutils"
4
+
5
+ module StreamdeckProf
6
+ class LazyFile
7
+ attr_accessor :source_path
8
+
9
+ def initialize(source_path)
10
+ @source_path = source_path
11
+ end
12
+
13
+ def save(path)
14
+ file_dir = File.dirname(path)
15
+ FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
16
+
17
+ FileUtils.copy(source_path, path) unless File.realdirpath(path) == File.realdirpath(source_path)
18
+ end
19
+ end
20
+ end
@@ -2,6 +2,8 @@
2
2
 
3
3
  require "json"
4
4
  require "streamdeck_prof/action"
5
+ require "streamdeck_prof/action_list"
6
+ require "streamdeck_prof/lazy_file"
5
7
 
6
8
  module StreamdeckProf
7
9
  class Profile
@@ -10,7 +12,6 @@ module StreamdeckProf
10
12
  def initialize(profile_dir)
11
13
  @profile_dir = profile_dir
12
14
  @manifest = JSON.parse(File.read(manifest_path))
13
- @actions_cache = {}
14
15
  end
15
16
 
16
17
  def uuid
@@ -33,26 +34,53 @@ module StreamdeckProf
33
34
  manifest["AppIdentifier"] = app_identifier
34
35
  end
35
36
 
36
- def action(x, y)
37
- key = "#{x},#{y}"
38
- return nil if @manifest["Actions"][key].nil?
39
-
40
- action!(x, y)
37
+ def actions
38
+ @actions ||= StreamdeckProf::ActionList.new.tap do |actions|
39
+ actions_hash = actions.to_h
40
+ manifest["Actions"].each do |key, value|
41
+ actions_hash[key] = make_action(key, value)
42
+ end
43
+ end
41
44
  end
42
45
 
43
- def action!(x, y)
44
- key = "#{x},#{y}"
45
- @actions_cache[key] ||= StreamdeckProf::Action.new(self, x, y)
46
+ def actions=(actions)
47
+ @actions = actions || StreamdeckProf::ActionList.new
46
48
  end
47
49
 
48
50
  def save
51
+ sync_manifest
52
+ @actions&.to_h&.each { |position_key, action| action.save(action_storage_path(position_key)) }
49
53
  File.write(manifest_path, JSON.dump(manifest))
50
54
  end
51
55
 
52
56
  private
53
57
 
58
+ def sync_manifest
59
+ manifest["Actions"] = actions.to_h.transform_values(&:to_h) unless @actions.nil?
60
+ end
61
+
54
62
  def manifest_path
55
63
  File.join(profile_dir, "manifest.json")
56
64
  end
65
+
66
+ def make_action(position_key, config)
67
+ StreamdeckProf::Action.new(config).tap do |action|
68
+ storage_path = action_storage_path(position_key)
69
+ Dir.glob(File.join(storage_path, "**/*"))
70
+ .reject { |path| File.directory?(path) }
71
+ .each do |path|
72
+ file_key = relative_path(storage_path, path)
73
+ action.files[file_key] = StreamdeckProf::LazyFile.new(path)
74
+ end
75
+ end
76
+ end
77
+
78
+ def action_storage_path(position_key)
79
+ File.join(profile_dir, position_key)
80
+ end
81
+
82
+ def relative_path(from_path, to_path)
83
+ Pathname.new(to_path).relative_path_from(Pathname.new(from_path)).to_s
84
+ end
57
85
  end
58
86
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StreamdeckProf
4
- VERSION = "0.1.1"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: streamdeck_prof
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Terce
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-04-14 00:00:00.000000000 Z
11
+ date: 2021-04-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -30,8 +30,11 @@ files:
30
30
  - bin/setup
31
31
  - lib/streamdeck_prof.rb
32
32
  - lib/streamdeck_prof/action.rb
33
+ - lib/streamdeck_prof/action_list.rb
33
34
  - lib/streamdeck_prof/context.rb
34
35
  - lib/streamdeck_prof/device_data.rb
36
+ - lib/streamdeck_prof/file_list.rb
37
+ - lib/streamdeck_prof/lazy_file.rb
35
38
  - lib/streamdeck_prof/profile.rb
36
39
  - lib/streamdeck_prof/version.rb
37
40
  - streamdeck_prof.gemspec