Class: Redmine::PluginPath

Inherits:
Object
  • Object
show all
Defined in:
lib/redmine/plugin_loader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir) ⇒ PluginPath

Returns a new instance of PluginPath.



24
25
26
27
28
# File 'lib/redmine/plugin_loader.rb', line 24

def initialize(dir)
  @dir = dir
  @assets_dir = File.join dir, 'assets'
  @initializer = File.join dir, 'init.rb'
end

Instance Attribute Details

#assets_dirObject (readonly)

Returns the value of attribute assets_dir.



22
23
24
# File 'lib/redmine/plugin_loader.rb', line 22

def assets_dir
  @assets_dir
end

#initializerObject (readonly)

Returns the value of attribute initializer.



22
23
24
# File 'lib/redmine/plugin_loader.rb', line 22

def initializer
  @initializer
end

Instance Method Details

#has_assets_dir?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/redmine/plugin_loader.rb', line 75

def has_assets_dir?
  File.directory?(@assets_dir)
end

#has_initializer?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/redmine/plugin_loader.rb', line 79

def has_initializer?
  File.file?(@initializer)
end

#mirror_assetsObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/redmine/plugin_loader.rb', line 38

def mirror_assets
  return unless has_assets_dir?

  destination = File.join(PluginLoader.public_directory, File.basename(@dir))

  source_files = Dir["#{assets_dir}/**/*"]
  source_dirs = source_files.select { |d| File.directory?(d)}
  source_files -= source_dirs
  unless source_files.empty?
    base_target_dir = File.join(destination, File.dirname(source_files.first).gsub(assets_dir, ''))
    begin
      FileUtils.mkdir_p(base_target_dir)
    rescue => e
      raise "Could not create directory #{base_target_dir}: " + e.message
    end
  end

  source_dirs.each do |dir|
    # strip down these paths so we have simple, relative paths we can
    # add to the destination
    target_dir = File.join(destination, dir.gsub(assets_dir, ''))
    begin
      FileUtils.mkdir_p(target_dir)
    rescue => e
      raise "Could not create directory #{target_dir}: " + e.message
    end
  end
  source_files.each do |file|
    target = File.join(destination, file.gsub(assets_dir, ''))
    unless File.exist?(target) && FileUtils.identical?(file, target)
      FileUtils.cp(file, target)
    end
  rescue => e
    raise "Could not copy #{file} to #{target}: " + e.message
  end
end

#run_initializerObject



30
31
32
# File 'lib/redmine/plugin_loader.rb', line 30

def run_initializer
  load initializer if has_initializer?
end

#to_sObject



34
35
36
# File 'lib/redmine/plugin_loader.rb', line 34

def to_s
  @dir
end