Class: Resource::Link

Inherits:
Base
  • Object
show all
Defined in:
lib/resource/link.rb

Instance Method Summary collapse

Methods inherited from Base

inherited, #not_if, #set_base_defaults, #should_skip?, #unix_mode

Methods included from ClassAttr

included

Methods included from BlockAttr

included

Constructor Details

#initialize(source, &block) ⇒ Link

Returns a new instance of Link.



7
8
9
10
11
12
# File 'lib/resource/link.rb', line 7

def initialize source, &block
  set_base_defaults
  @source = source
  @to = 'no_target'
  self.instance_eval(&block)
end

Instance Method Details

#runObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/resource/link.rb', line 14

def run
  Execution.block 'Building Link', "#{@source} ~> #{@to}", @owner do |b|
    b.always_run @always_run
    b.run "mkdir -p #{::File.dirname(@to)}"
    b.run "mkdir -p #{::File.dirname(@source)}" unless ::File.exist?(::File.dirname(@source))
    b.run "touch #{@source}"
    b.run "rm -rf #{@source}"
    b.run "ln -s #{@to} #{@source}"
  end
end