Class: Tankobon::Stageable

Inherits:
Object
  • Object
show all
Defined in:
lib/tankobon/stageable.rb

Direct Known Subclasses

Archive, Directory

Instance Method Summary collapse

Constructor Details

#initialize(stageable) ⇒ Stageable

Returns a new instance of Stageable.



5
6
7
# File 'lib/tankobon/stageable.rb', line 5

def initialize(stageable)
  @stageable = Pathname.new(stageable)
end

Instance Method Details

#stageObject



13
14
15
# File 'lib/tankobon/stageable.rb', line 13

def stage
  stage_root + @stageable.basename('.*')
end

#stage_rootObject



9
10
11
# File 'lib/tankobon/stageable.rb', line 9

def stage_root
  Pathname.new("~/tankobon2").expand_path
end

#stageableObject



17
18
19
# File 'lib/tankobon/stageable.rb', line 17

def stageable
  @stageable.expand_path
end

#to_stage(&block) ⇒ Object



21
22
23
24
25
26
# File 'lib/tankobon/stageable.rb', line 21

def to_stage(&block)
  FileUtils.mkdir_p(stage.dirname) unless stage.dirname.exist?
  FileUtils.rm_r(stage) if stage.exist?
  yield if block_given?
  StagedDirectory.new(stage)
end