Class: Naether::Java::JRuby

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/naether/java.rb

Overview

Handle loading jars for JRuby

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeJRuby

Returns a new instance of JRuby.



84
85
86
87
88
89
# File 'lib/naether/java.rb', line 84

def initialize
  require 'java'
  
  @loaded_jars = []
  @loaded_paths = []
end

Instance Attribute Details

#loaded_jarsObject (readonly)

Returns the value of attribute loaded_jars.



82
83
84
# File 'lib/naether/java.rb', line 82

def loaded_jars
  @loaded_jars
end

#loaded_pathsObject (readonly)

Returns the value of attribute loaded_paths.



82
83
84
# File 'lib/naether/java.rb', line 82

def loaded_paths
  @loaded_paths
end

Instance Method Details

#convert_to_ruby_array(java_array, to_string = false) ⇒ Object



136
137
138
# File 'lib/naether/java.rb', line 136

def convert_to_ruby_array( java_array, to_string = false )
  java_array.to_a
end

#convert_to_ruby_hash(java_hash, to_string = false) ⇒ Object



140
141
142
# File 'lib/naether/java.rb', line 140

def convert_to_ruby_hash( java_hash, to_string = false )
  java_hash.to_hash
end

#create(target_class, *args) ⇒ Object



91
92
93
94
# File 'lib/naether/java.rb', line 91

def create( target_class, *args )
  java_class = java_class(target_class)
  java_class.new( *args )
end

#java_class(target_class) ⇒ Object



96
97
98
# File 'lib/naether/java.rb', line 96

def java_class( target_class ) 
  eval(target_class)
end

#load_jars(jars) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/naether/java.rb', line 118

def load_jars(jars)
  load_jars = []
  unless jars.is_a? Array
    jars = [jars]
  end
  
  jars.each do |jar|
    expanded_jar = File.expand_path(jar)
    if !@loaded_jars.include? expanded_jar
      require expanded_jar
      load_jars << expanded_jar
      @loaded_jars << expanded_jar
    end
  end
  
  load_jars
end

#load_paths(paths) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/naether/java.rb', line 100

def load_paths(paths)
  load_paths = []
  unless paths.is_a? Array
    paths = [paths]
  end
  
  paths.each do |path|
    expanded_path = File.expand_path(path)
    if !@loaded_paths.include? expanded_path
      $CLASSPATH << expanded_path
      load_paths << expanded_path
      @loaded_paths << expanded_path
    end
  end
  
  load_paths
end