Class: JBundler::ClasspathFile

Inherits:
Object
  • Object
show all
Defined in:
lib/jbundler/classpath_file.rb

Instance Method Summary collapse

Constructor Details

#initialize(classpathfile = '.jbundler/classpath.rb') ⇒ ClasspathFile

Returns a new instance of ClasspathFile.



5
6
7
# File 'lib/jbundler/classpath_file.rb', line 5

def initialize(classpathfile = '.jbundler/classpath.rb')
  @classpathfile = classpathfile
end

Instance Method Details

#exists?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/jbundler/classpath_file.rb', line 17

def exists?
  File.exists?(@classpathfile)
end

#generate(classpath) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/jbundler/classpath_file.rb', line 25

def generate(classpath)
  FileUtils.mkdir_p(File.dirname(@classpathfile))
  File.open(@classpathfile, 'w') do |f|
    f.puts "JBUNDLER_CLASSPATH = []"
    classpath.split(/#{File::PATH_SEPARATOR}/).each do |path|
      f.puts "JBUNDLER_CLASSPATH << '#{path}'" unless path =~ /pom$/
    end
    f.puts "JBUNDLER_CLASSPATH.freeze"
    f.puts "JBUNDLER_CLASSPATH.each { |c| require c }"
    f.close
  end
end

#mtimeObject



13
14
15
# File 'lib/jbundler/classpath_file.rb', line 13

def mtime
  File.mtime(@classpathfile)
end

#needs_update?(jarfile, gemfile_lock) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/jbundler/classpath_file.rb', line 21

def needs_update?(jarfile, gemfile_lock)
  !exists? || !jarfile.exists_lock? || (jarfile.exists? && (jarfile.mtime > mtime)) || (jarfile.exists_lock? && (jarfile.mtime_lock > mtime)) || (gemfile_lock.mtime > mtime)
end

#require_classpathObject



9
10
11
# File 'lib/jbundler/classpath_file.rb', line 9

def require_classpath
  load File.expand_path @classpathfile
end