Class: Mnogootex::Job::Porter

Inherits:
Object
  • Object
show all
Defined in:
lib/mnogootex/job/porter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hid:, source_path:) ⇒ Porter



13
14
15
16
# File 'lib/mnogootex/job/porter.rb', line 13

def initialize(hid:, source_path:)
  @source_path = Pathname.new(source_path).realpath
  @hid = hid
end

Instance Attribute Details

#hidObject (readonly)

Returns the value of attribute hid.



11
12
13
# File 'lib/mnogootex/job/porter.rb', line 11

def hid
  @hid
end

Instance Method Details

#clobberObject



26
27
28
# File 'lib/mnogootex/job/porter.rb', line 26

def clobber
  target_dir.rmtree if target_dir.directory?
end

#provideObject



30
31
32
33
34
35
36
# File 'lib/mnogootex/job/porter.rb', line 30

def provide
  target_dir.mkpath
  # NOTE: can't use Pathname.join here since it elides the dot:
  FileUtils.cp_r File.join(@source_path.dirname, '.'), target_dir
  target_dir.join('.mnogootex.yml').tap { |p| p.delete if p.file? }
  target_dir.join('.mnogootex.src').make_symlink(@source_path)
end

#target_dirObject



18
19
20
# File 'lib/mnogootex/job/porter.rb', line 18

def target_dir
  @target_dir ||= Pathname.new(Dir.tmpdir).join('mnogootex', source_id, hid)
end

#target_pathObject



22
23
24
# File 'lib/mnogootex/job/porter.rb', line 22

def target_path
  @target_path ||= target_dir.join(@source_path.basename)
end