Skip to content

Commit 9a2e3a6

Browse files
committed
refactor still violates reek rules
1 parent 165146b commit 9a2e3a6

File tree

2 files changed

+43
-35
lines changed

2 files changed

+43
-35
lines changed

lib/jruby_art/installer.rb

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,18 @@
33

44
VERSION = '3.1.1' # processing version
55

6+
# Abstract Installer class
67
class Installer
78
attr_reader :os, :sketch, :gem_root, :home
8-
def initialize(os: :linux, root:)
9+
def initialize(root, os)
910
@os = os
1011
@gem_root = root
1112
@home = ENV['HOME']
1213
@sketch = "#{home}/sketchbook" if os == :linux
1314
@sketch = "#{home}/My Documents/Processing" if os == :windows
1415
@sketch = "#{home}/Documents/Processing" if os == :mac
1516
end
16-
17-
def install
18-
system "cd #{gem_root}/vendors && rake"
19-
return if root_exist?
20-
set_processing_root
21-
warn 'PROCESSING_ROOT set optimistically, run check to confirm'
22-
end
23-
24-
def install_examples
25-
system "cd #{gem_root}/vendors && rake unpack_samples"
26-
end
27-
17+
2818
# Optimistically set processing root
2919
def set_processing_root
3020
require 'psych'
@@ -40,22 +30,36 @@ def set_processing_root
4030
'sketchbook_path' => sketch,
4131
'MAX_WATCH' => '20'
4232
}
43-
open(path, 'w:UTF-8') { |f| f.write(data.to_yaml) }
33+
open(path, 'w:UTF-8') { |file| file.write(data.to_yaml) }
4434
end
45-
35+
4636
def root_exist?
4737
return false if config.nil?
4838
File.exist? config['PROCESSING_ROOT']
4939
end
50-
40+
5141
def config
5242
k9config = File.expand_path("#{home}/.jruby_art/config.yml")
5343
return nil unless File.exist? k9config
5444
YAML.load_file(k9config)
5545
end
46+
47+
# in place of default installer class
48+
def install
49+
puts 'Usage: k9 setup [check | install | unpack_samples]'
50+
end
51+
52+
# Display the current version of JRubyArt.
53+
def show_version
54+
puts format('JRubyArt version %s', JRubyArt::VERSION)
55+
end
56+
end
5657

57-
def check
58+
# Configuration checker
59+
class Check < Installer
60+
def install
5861
show_version
62+
return super unless config
5963
installed = File.exist? File.join(gem_root, 'lib/ruby/jruby-complete.jar')
6064
proot = ' PROCESSING_ROOT = Not Set!!!' unless root_exist?
6165
proot ||= " PROCESSING_ROOT = #{config['PROCESSING_ROOT']}"
@@ -68,9 +72,21 @@ def check
6872
puts sketchbook
6973
puts max_watch
7074
end
75+
end
7176

72-
# Display the current version of JRubyArt.
73-
def show_version
74-
puts format('JRubyArt version %s', JRubyArt::VERSION)
77+
# Examples Installer
78+
class UnpackSamples < Installer
79+
def install
80+
system "cd #{gem_root}/vendors && rake unpack_samples"
81+
end
82+
end
83+
84+
# JRuby-Complete installer
85+
class JRubyComplete < Installer
86+
def install
87+
system "cd #{gem_root}/vendors && rake"
88+
return if root_exist?
89+
set_processing_root
90+
warn 'PROCESSING_ROOT set optimistically, run check to confirm'
7591
end
7692
end

lib/jruby_art/runner.rb

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -118,20 +118,13 @@ def live(sketch, args)
118118
def watch(sketch, args)
119119
ensure_exists(sketch)
120120
spin_up('watch.rb', sketch, args)
121-
end
121+
end
122122

123-
def setup(choice)
124-
installer = Installer.new(root: K9_ROOT, os: host_os)
125-
case choice
126-
when /check/
127-
installer.check
128-
when /install/
129-
installer.install
130-
when /unpack_samples/
131-
installer.install_examples
132-
else
133-
puts 'Usage: k9 setup [check | install | unpack_samples]'
134-
end
123+
def setup(choice)
124+
return Check.new(K9_ROOT, host_os).install if choice =~ /check/
125+
return JRubyComplete.new(K9_ROOT, host_os).install if choice if choice =~ /install/
126+
return UnpackSamples.new(K9_ROOT, host_os).install if choice =~ /unpack_sample/
127+
Installer.new(K9_ROOT, host_os).install
135128
end
136129

137130
# Show the standard help/usage message.
@@ -171,8 +164,7 @@ def spin_up(starter_script, sketch, args)
171164
# exec replaces the Ruby process with the JRuby one.
172165
rescue Java::JavaLang::ClassNotFoundException
173166
end
174-
end
175-
167+
end
176168

177169
# NB: We really do mean to use 'and' not '&&' for flow control purposes
178170

0 commit comments

Comments
 (0)