jruby_art 1.2.9 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5a546d2ddb8d8bec07eff66933fe94a58a9b4bfe
4
- data.tar.gz: 9169d2704cedb767444c204c364bcc679667bf51
3
+ metadata.gz: 292fae4f648b4f0327554d767cdd4640402a16c8
4
+ data.tar.gz: 8110acac7375c71c172b7874fa1de38ac107bfc5
5
5
  SHA512:
6
- metadata.gz: 4c30db2ffa7956684c7c526f68bef2e7f0ed120a231d64d3fafae2700e0169f6f366f8ae3a805ed4a8406cfcf416ed6be3a28afaebaacd7bf547d0e6d8c3af48
7
- data.tar.gz: 07be0723e66c76b74dc982040ea2baa2e5711d3a430650bc09fde36f8cbd73492f53950321eae41071ffa109c2349d20cc93342b72e5b24f4fb4545c19d6ce27
6
+ metadata.gz: b722c4cc150a52923b144b3dbc6397bc79a66fdeaf3233c51f991d4e61a6308202aa16a0f28cc907edb35e6e4c3f5982a64f430e9a7d921cd0a1481344607427
7
+ data.tar.gz: 74a19e1bd0f7495b176073a9e5d857c56b0b2aae464e8d46180f69d9e2a6f60ac5e334f591d4bb4896becf9c423b81cbc5f343a99bf9619f9dd31b17ce2fe1e3
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+ # module encapsulates a check that the PROCESSING_ROOT exists
3
+ module Core
4
+ def self.check?(path)
5
+ if File.directory?(path)
6
+ core_path = File.join(path, 'core/library/core.jar')
7
+ return true if File.exist?(core_path)
8
+ warn format('%s jar does not exist', core_path)
9
+ else warn format('%s directory does not exist', path)
10
+ end
11
+ end
12
+ end
13
+
14
+ # Provided processing distributions have the same nested structure ie:-
15
+ # "core/library/core.jar" we can find "core.jar" when PROCESSING_ROOT exists
@@ -33,8 +33,7 @@ class SketchWriter
33
33
  end
34
34
 
35
35
  def write
36
- template = SketchTemplate.template
37
- sketch = template.code(param)
36
+ sketch = SketchFactory.create(param)
38
37
  File.open(file, 'w+') { |f| f.write sketch.join("\n") }
39
38
  end
40
39
  end
@@ -42,19 +41,26 @@ end
42
41
  # Implements methods and class_methods omits blank line after draw
43
42
  # uses private method_lines to format method lines
44
43
  class Sketch
44
+ attr_reader :param
45
+
46
+ def initialize(param)
47
+ @param = param
48
+ self
49
+ end
50
+
45
51
  BLANK ||= ''.freeze
46
52
  INDENT ||= ' '.freeze
47
53
 
48
- def methods(param, indent)
54
+ def methods(indent)
49
55
  lines = []
50
56
  lines.concat method_lines('settings', param.sketch_size, indent)
51
57
  lines.concat method_lines('setup', param.sketch_title, indent)
52
58
  lines.concat method_lines('draw', BLANK, indent)
53
59
  end
54
60
 
55
- def class_methods(param)
61
+ def class_methods
56
62
  lines = [format('class %s < Processing::App', param.class_name)]
57
- lines.concat methods(param, INDENT)
63
+ lines.concat methods(INDENT)
58
64
  lines << 'end'
59
65
  end
60
66
 
@@ -70,37 +76,37 @@ class Sketch
70
76
  end
71
77
 
72
78
  # Switch templates on config
73
- class SketchTemplate
74
- def self.template
79
+ class SketchFactory
80
+ def self.create(param)
75
81
  case Processing::RP_CONFIG.fetch('template', 'bare')
76
82
  when /bare/
77
- return BareSketch.new
83
+ BareSketch
78
84
  when /class/
79
- return ClassSketch.new
85
+ ClassSketch
80
86
  when /emacs/
81
- return EmacsSketch.new
82
- end
87
+ EmacsSketch
88
+ end.new(param).code
83
89
  end
84
90
  end
85
91
 
86
92
  # The sketch class creates an array of formatted sketch lines
87
93
  class BareSketch < Sketch
88
- def code(param)
89
- methods(param, BLANK)
94
+ def code
95
+ methods(BLANK)
90
96
  end
91
97
  end
92
98
 
93
99
  # A simple class wrapped sketch
94
100
  class ClassSketch < Sketch
95
- def code(param)
101
+ def code
96
102
  lines = ['# frozen_string_literal: false', BLANK]
97
- lines.concat class_methods(param)
103
+ lines.concat class_methods
98
104
  end
99
105
  end
100
106
 
101
107
  # A sketch that will run with jruby, for emacs etc
102
108
  class EmacsSketch < Sketch
103
- def code(param)
109
+ def code
104
110
  lines = [
105
111
  '# frozen_string_literal: false',
106
112
  "require 'jruby_art'",
@@ -109,7 +115,7 @@ class EmacsSketch < Sketch
109
115
  'Processing::App::SKETCH_PATH = __FILE__.freeze',
110
116
  BLANK
111
117
  ]
112
- lines.concat class_methods(param)
118
+ lines.concat class_methods
113
119
  lines << BLANK
114
120
  lines << format('%s.new unless defined? $app', param.class_name)
115
121
  end
@@ -76,16 +76,19 @@ module Processing
76
76
 
77
77
  # explicitly provide 'processing.org' min instance method
78
78
  # to return a float:- a, b and c need to be floats
79
+ # you might choose to use ruby method directly and then
80
+ # provide a block to alter comparator eg
81
+ # args.min(&block) # { |a, b| a.value <=> b.value }
79
82
 
80
83
  def min(*args)
81
- args.min # { |a,b| a <=> b } optional block not reqd
84
+ args.min
82
85
  end
83
86
 
84
87
  # explicitly provide 'processing.org' max instance method
85
- # to return a float:- a, b and c need to be floats
88
+ # to return a float:- a, b and c need to be floats see above
86
89
 
87
90
  def max(*args)
88
- args.max # { |a, b| a <=> b } optional block not reqd
91
+ args.max
89
92
  end
90
93
 
91
94
  # explicitly provide 'processing.org' dist instance method
@@ -31,8 +31,7 @@ class Installer
31
31
  end
32
32
 
33
33
  def root_exist?
34
- return false if config.empty?
35
- File.exist? config['PROCESSING_ROOT']
34
+ Core.check?(config['PROCESSING_ROOT'])
36
35
  end
37
36
 
38
37
  def config
@@ -55,12 +54,13 @@ end
55
54
 
56
55
  # Configuration checker
57
56
  class Check < Installer
57
+ require_relative 'core'
58
58
  def install
59
59
  show_version
60
60
  return super unless config
61
61
  installed = File.exist? File.join(gem_root, 'lib/ruby/jruby-complete.jar')
62
- proot = ' PROCESSING_ROOT = Not Set!!!' unless root_exist?
63
- proot ||= " PROCESSING_ROOT = #{config['PROCESSING_ROOT']}"
62
+ proot = ' PROCESSING_ROOT = Not Set Correctly!!!' unless root_exist?
63
+ proot ||= " PROCESSING_ROOT = #{config['PROCESSING_ROOT']}"
64
64
  sketchbook = " sketchbook_path = #{config['sketchbook_path']}"
65
65
  template = " template = #{config['template']}"
66
66
  java_args = " java_args = #{config['java_args']}"
@@ -3,13 +3,12 @@
3
3
  class JavaOpts
4
4
  attr_reader :opts
5
5
 
6
- def initialize(sketch_root)
7
- arg_file = File.join(sketch_root, 'data/java_args.txt')
6
+ def initialize
7
+ arg_file = File.join(SKETCH_ROOT, 'data/java_args.txt')
8
8
  @opts = []
9
9
  @opts += File.read(arg_file).split(/\s+/) if FileTest.exist?(arg_file)
10
- if opts.empty? && Processing::RP_CONFIG.fetch('java_args', false)
11
- @opts += Processing::RP_CONFIG['java_args'].split(/\s+/)
12
- end
10
+ return unless opts.empty? && Processing::RP_CONFIG.fetch('java_args', false)
11
+ @opts += Processing::RP_CONFIG['java_args'].split(/\s+/)
13
12
  end
14
13
  end
15
14
 
@@ -5,11 +5,13 @@ module Processing
5
5
  # The command class check for configuration and options, before creating and
6
6
  # executing the jruby (or java) command to run the sketch
7
7
  class Launcher
8
- attr_reader :runner, :args, :filename
8
+ attr_reader :command
9
9
  def initialize(runner:, args:, filename:)
10
- @runner = runner
11
- @args = args
12
- @filename = filename
10
+ @command = if Processing::RP_CONFIG.fetch('JRUBY', true)
11
+ JRubyCommand.new(runner, filename, args)
12
+ else
13
+ JavaCommand.new(runner, filename, args)
14
+ end
13
15
  end
14
16
 
15
17
  # Trade in this Ruby instance for a JRuby instance, loading in a starter
@@ -17,25 +19,41 @@ module Processing
17
19
  # ~/.jruby_art/config.yml, an installed version of jruby is used instead
18
20
  # of our vendored one. Note the use of jruby-complete might make using
19
21
  # other gems in your sketches hard (but not impossible)....
20
- def cmd(root)
21
- cmda = jruby_command(root)
22
+ def cmd
23
+ cmda = command.cmd
22
24
  begin
23
25
  exec(*cmda)
24
26
  # exec replaces the Ruby process with the JRuby one.
25
27
  rescue Java::JavaLang::ClassNotFoundException
26
28
  end
27
29
  end
30
+ end
31
+ end
28
32
 
29
- private
33
+ # Wrap creation of java command string as a class
34
+ class JavaCommand
35
+ MAIN = 'org.jruby.Main'.freeze
36
+ attr_reader :runner, :args, :filename, :opts, :complete
37
+ def initialize(runner, args, filename)
38
+ @runner, @args, @filename = runner, args, filename
39
+ @complete = JRubyComplete.complete
40
+ @opts = JavaOpts.new.opts
41
+ end
30
42
 
31
- # avoiding multiline ternary etc
32
- def jruby_command(root)
33
- installed = Processing::RP_CONFIG.fetch('JRUBY', true)
34
- opts = JRubyOpts.new(root).opts
35
- return ['jruby', opts, runner, filename, args].flatten if installed
36
- opts = JavaOpts.new(root).opts
37
- complete = JRubyComplete.complete
38
- ['java', opts, '-cp', complete, 'org.jruby.Main', runner, filename, args].flatten
39
- end
43
+ def cmd
44
+ ['java', opts, '-cp', complete, MAIN, runner, filename, args].flatten
45
+ end
46
+ end
47
+
48
+ # Wrap creation of jruby command string as a class
49
+ class JRubyCommand
50
+ attr_reader :runner, :args, :filename, :opts
51
+ def initialize(runner, args, filename)
52
+ @runner, @args, @filename = runner, args, filename
53
+ @opts = JRubyOpts.new.opts
54
+ end
55
+
56
+ def cmd
57
+ ['jruby', opts, runner, filename, args].flatten
40
58
  end
41
59
  end
@@ -166,7 +166,7 @@ module Processing
166
166
  args: argc,
167
167
  filename: filename
168
168
  )
169
- launch.cmd(SKETCH_ROOT)
169
+ launch.cmd
170
170
  end
171
171
 
172
172
  # NB: We really do mean to use 'and' not '&&' for flow control purposes
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  # A wrapper for version
3
3
  module JRubyArt
4
- VERSION = '1.2.9'.freeze
4
+ VERSION = '1.3.0'.freeze
5
5
  end
Binary file
@@ -8,8 +8,8 @@ WARNING = <<-EOS.freeze
8
8
 
9
9
  EOS
10
10
 
11
- JRUBYC_VERSION = '9.1.7.0'
12
- EXAMPLES = '2.0'
11
+ JRUBYC_VERSION = '9.1.8.0'
12
+ EXAMPLES = '2.1'
13
13
  HOME_DIR = ENV['HOME']
14
14
  MAC_OR_LINUX = /linux|mac|darwin/ =~ RbConfig::CONFIG['host_os']
15
15
 
@@ -27,7 +27,7 @@ file "jruby-complete-#{JRUBYC_VERSION}.jar" do
27
27
  rescue
28
28
  warn(WARNING)
29
29
  end
30
- check_sha256("jruby-complete-#{JRUBYC_VERSION}.jar", "62983e2b6360005a65931b1cd5a5b50aa97168407feb29410454e658204521de")
30
+ check_sha256("jruby-complete-#{JRUBYC_VERSION}.jar", "f4552ce55ac6700ad51dc1dce8a3a0b8153cbe9b885006e039a98b558f77e551")
31
31
  end
32
32
 
33
33
  directory "../lib/ruby"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jruby_art
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.9
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Ashkenas
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-02-14 00:00:00.000000000 Z
13
+ date: 2017-03-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
@@ -53,6 +53,7 @@ files:
53
53
  - lib/jruby_art.rb
54
54
  - lib/jruby_art/app.rb
55
55
  - lib/jruby_art/config.rb
56
+ - lib/jruby_art/core.rb
56
57
  - lib/jruby_art/creators/sketch_writer.rb
57
58
  - lib/jruby_art/helper_methods.rb
58
59
  - lib/jruby_art/helpers/aabb.rb