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:, work_path: nil) ⇒ Porter

Returns a new instance of Porter.



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

def initialize(hid:, source_path:, work_path: nil)
  @source_path = Pathname.new(source_path).realpath
  @work_path = calc_work_path(work_path).tap(&:mkpath).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



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

def clobber
  target_dir.rmtree if target_dir.directory?
end

#provideObject



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

def provide
  target_dir.mkpath
  providable_files = @source_path.dirname.children
  providable_files.reject!(&@work_path.method(:==))
  FileUtils.cp_r providable_files, target_dir
  remove_configuration(target_dir)
  create_link_to_source(target_dir)
end

#target_dirObject



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

def target_dir
  @target_dir ||= @work_path.join(hid)
end

#target_pathObject



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

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