Class: Dply::Linker
- Inherits:
-
Object
show all
- Includes:
- Helper
- Defined in:
- lib/dply/linker.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Helper
#cmd, #error, #git, #logger, #stringify_values!, #symlink
Constructor Details
#initialize(src_dir, dest_dir, map: {}) ⇒ Linker
Returns a new instance of Linker.
9
10
11
12
13
14
|
# File 'lib/dply/linker.rb', line 9
def initialize(src_dir, dest_dir, map: {})
verify_absolute src_dir, dest_dir
@src_dir = src_dir
@dest_dir = dest_dir
@map = map
end
|
Instance Attribute Details
#dest_dir ⇒ Object
Returns the value of attribute dest_dir.
7
8
9
|
# File 'lib/dply/linker.rb', line 7
def dest_dir
@dest_dir
end
|
#map ⇒ Object
Returns the value of attribute map.
7
8
9
|
# File 'lib/dply/linker.rb', line 7
def map
@map
end
|
#src_dir ⇒ Object
Returns the value of attribute src_dir.
7
8
9
|
# File 'lib/dply/linker.rb', line 7
def src_dir
@src_dir
end
|
Instance Method Details
#create_symlinks ⇒ Object
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/dply/linker.rb', line 16
def create_symlinks
mapped_files.each do |f|
target = link_target(f)
source = link_source(f)
relative_source = link_relative_source(source, target)
logger.debug "linking #{target} -> #{source}"
error "source #{source} doesn't exist" if not File.exist? source
symlink(relative_source, target)
end
end
|
#link_relative_source(source, target) ⇒ Object
36
37
38
|
# File 'lib/dply/linker.rb', line 36
def link_relative_source(source, target)
source.relative_path_from target.parent
end
|
#link_source(relative_target) ⇒ Object
31
32
33
34
|
# File 'lib/dply/linker.rb', line 31
def link_source(relative_target)
relative_source = map[relative_target]
Pathname.new "#{src_dir}/#{relative_source}"
end
|
#link_target(relative_target) ⇒ Object
27
28
29
|
# File 'lib/dply/linker.rb', line 27
def link_target(relative_target)
Pathname.new "#{dest_dir}/#{relative_target}"
end
|
#mapped_files ⇒ Object
40
41
42
43
44
45
46
|
# File 'lib/dply/linker.rb', line 40
def mapped_files
map.keys.collect do |k|
path = Pathname.new k
raise "config map path cannot be absoulte" if path.absolute?
k
end
end
|
#verify_absolute(*paths) ⇒ Object
48
49
50
51
52
53
|
# File 'lib/dply/linker.rb', line 48
def verify_absolute(*paths)
paths.each do |path|
absolute = Pathname.new(path).absolute?
raise "#{path} not absolute" if not absolute
end
end
|