Class: Jekyll::Compose::FileMover

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll-compose/file_mover.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(movement, root = nil) ⇒ FileMover

Returns a new instance of FileMover.



5
6
7
8
# File 'lib/jekyll-compose/file_mover.rb', line 5

def initialize(movement, root = nil)
  @movement = movement
  @root = root
end

Instance Attribute Details

#movementObject (readonly)

Returns the value of attribute movement.



4
5
6
# File 'lib/jekyll-compose/file_mover.rb', line 4

def movement
  @movement
end

#rootObject (readonly)

Returns the value of attribute root.



4
5
6
# File 'lib/jekyll-compose/file_mover.rb', line 4

def root
  @root
end

Instance Method Details

#ensure_directory_existsObject



24
25
26
27
# File 'lib/jekyll-compose/file_mover.rb', line 24

def ensure_directory_exists
  dir = File.dirname to
  Dir.mkdir(dir) unless Dir.exist?(dir)
end

#moveObject



14
15
16
17
18
# File 'lib/jekyll-compose/file_mover.rb', line 14

def move
  validate_source
  ensure_directory_exists
  move_file
end

#move_fileObject



29
30
31
32
# File 'lib/jekyll-compose/file_mover.rb', line 29

def move_file
  FileUtils.mv(from, to)
  puts "#{resource_type.capitalize} #{from} was moved to #{to}"
end

#resource_typeObject



10
11
12
# File 'lib/jekyll-compose/file_mover.rb', line 10

def resource_type
  "file"
end

#validate_sourceObject

Raises:

  • (ArgumentError)


20
21
22
# File 'lib/jekyll-compose/file_mover.rb', line 20

def validate_source
  raise ArgumentError, "There was no #{resource_type} found at '#{from}'." unless File.exist? from
end