Class: Jekyll::Compose::FileMover
- Inherits:
-
Object
- Object
- Jekyll::Compose::FileMover
show all
- Defined in:
- lib/jekyll-compose/file_mover.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(movement, force = false, root = nil) ⇒ FileMover
Returns a new instance of FileMover.
7
8
9
10
11
|
# File 'lib/jekyll-compose/file_mover.rb', line 7
def initialize(movement, force = false, root = nil)
@movement = movement
@force = force
@root = root
end
|
Instance Attribute Details
#force ⇒ Object
Returns the value of attribute force.
6
7
8
|
# File 'lib/jekyll-compose/file_mover.rb', line 6
def force
@force
end
|
#movement ⇒ Object
Returns the value of attribute movement.
6
7
8
|
# File 'lib/jekyll-compose/file_mover.rb', line 6
def movement
@movement
end
|
#root ⇒ Object
Returns the value of attribute root.
6
7
8
|
# File 'lib/jekyll-compose/file_mover.rb', line 6
def root
@root
end
|
Instance Method Details
#ensure_directory_exists ⇒ Object
32
33
34
35
|
# File 'lib/jekyll-compose/file_mover.rb', line 32
def ensure_directory_exists
dir = File.dirname to
Dir.mkdir(dir) unless Dir.exist?(dir)
end
|
#move ⇒ Object
21
22
23
24
25
26
|
# File 'lib/jekyll-compose/file_mover.rb', line 21
def move
validate_source
validate_should_write!
ensure_directory_exists
move_file
end
|
#move_file ⇒ Object
41
42
43
44
|
# File 'lib/jekyll-compose/file_mover.rb', line 41
def move_file
FileUtils.mv(from, to)
puts "#{resource_type_from.capitalize} #{from} was moved to #{to}"
end
|
#resource_type_from ⇒ Object
13
14
15
|
# File 'lib/jekyll-compose/file_mover.rb', line 13
def resource_type_from
"file"
end
|
#resource_type_to ⇒ Object
17
18
19
|
# File 'lib/jekyll-compose/file_mover.rb', line 17
def resource_type_to
"file"
end
|
#validate_should_write! ⇒ Object
37
38
39
|
# File 'lib/jekyll-compose/file_mover.rb', line 37
def validate_should_write!
raise ArgumentError, "A #{resource_type_to} already exists at #{to}" if File.exist?(to) && !force
end
|
#validate_source ⇒ Object
28
29
30
|
# File 'lib/jekyll-compose/file_mover.rb', line 28
def validate_source
raise ArgumentError, "There was no #{resource_type_from} found at '#{from}'." unless File.exist? from
end
|