Skip to content

Commit 037fb72

Browse files
committed
refactor library_loader to library_loader and sketchbook module
1 parent b41740c commit 037fb72

File tree

2 files changed

+27
-24
lines changed

2 files changed

+27
-24
lines changed

lib/jruby_art/library_loader.rb

+3-24
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
# frozen_string_literal: false
33

44
require_relative '../jruby_art'
5-
5+
require_relative 'sketchbook'
66
# The processing wrapper module
77
module Processing
88
# Encapsulate library loader functionality as a class
99
class LibraryLoader
1010
attr_reader :sketchbook_library_path
1111

1212
def initialize
13-
@sketchbook_library_path = File.join(find_sketchbook_path, 'libraries')
13+
@sketchbook_library_path = File.join(Sketchbook.find_path, 'libraries')
1414
@loaded_libraries = Hash.new(false)
1515
end
1616

@@ -117,27 +117,6 @@ def get_library_directory_path(library_name, extension = nil)
117117
end
118118
end
119119
nil
120-
end
121-
122-
def find_sketchbook_path
123-
preferences_paths = []
124-
sketchbook_paths = []
125-
sketchbook_path = Processing::RP_CONFIG.fetch('sketchbook_path', false)
126-
return sketchbook_path if sketchbook_path
127-
[
128-
"'Application Data/Processing'", 'AppData/Roaming/Processing',
129-
'Library/Processing', 'Documents/Processing',
130-
'.processing', 'sketchbook'
131-
].each do |prefix|
132-
spath = format('%s/%s', ENV['HOME'], prefix)
133-
pref_path = format('%s/preferences.txt', spath)
134-
preferences_paths << pref_path if FileTest.file?(pref_path)
135-
sketchbook_paths << spath if FileTest.directory?(spath)
136-
end
137-
return sketchbook_paths.first if preferences_paths.empty?
138-
lines = IO.readlines(preferences_paths.first)
139-
matchedline = lines.grep(/^sketchbook/).first
140-
matchedline[/=(.+)/].delete('=')
141-
end
120+
end
142121
end
143122
end

lib/jruby_art/sketchbook.rb

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# frozen_string_literal: false
2+
# Utility to find sketchbook and hence java libraries
3+
module Sketchbook
4+
def self.find_path
5+
preferences_paths = []
6+
sketchbook_paths = []
7+
sketchbook_path = Processing::RP_CONFIG.fetch('sketchbook_path', false)
8+
return sketchbook_path if sketchbook_path
9+
[
10+
"'Application Data/Processing'", 'AppData/Roaming/Processing',
11+
'Library/Processing', 'Documents/Processing',
12+
'.processing', 'sketchbook'
13+
].each do |prefix|
14+
spath = format('%s/%s', ENV['HOME'], prefix)
15+
pref_path = format('%s/preferences.txt', spath)
16+
preferences_paths << pref_path if FileTest.file?(pref_path)
17+
sketchbook_paths << spath if FileTest.directory?(spath)
18+
end
19+
return sketchbook_paths.first if preferences_paths.empty?
20+
lines = IO.readlines(preferences_paths.first)
21+
matchedline = lines.grep(/^sketchbook/).first
22+
matchedline[/=(.+)/].delete('=')
23+
end
24+
end

0 commit comments

Comments
 (0)