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.



25
26
27
# File 'lib/jbundler/classpath_file.rb', line 25

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

Instance Method Details

#exists?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/jbundler/classpath_file.rb', line 37

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

#generate(classpath_array) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/jbundler/classpath_file.rb', line 45

def generate(classpath_array)
  FileUtils.mkdir_p(File.dirname(@classpathfile))
  File.open(@classpathfile, 'w') do |f|
    f.puts "JBUNDLER_CLASSPATH = []"
    classpath_array.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



33
34
35
# File 'lib/jbundler/classpath_file.rb', line 33

def mtime
  File.mtime(@classpathfile)
end

#needs_update?(jarfile, gemfile_lock) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/jbundler/classpath_file.rb', line 41

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

#require_classpathObject



29
30
31
# File 'lib/jbundler/classpath_file.rb', line 29

def require_classpath
  load File.expand_path @classpathfile
end