Class: Bunto::Compose::FileMover
- Inherits:
-
Object
- Object
- Bunto::Compose::FileMover
show all
- Defined in:
- lib/bunto-compose/file_mover.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(movement) ⇒ FileMover
Returns a new instance of FileMover.
5
6
7
|
# File 'lib/bunto-compose/file_mover.rb', line 5
def initialize(movement)
@movement = movement
end
|
Instance Attribute Details
#movement ⇒ Object
Returns the value of attribute movement.
4
5
6
|
# File 'lib/bunto-compose/file_mover.rb', line 4
def movement
@movement
end
|
Instance Method Details
#ensure_directory_exists ⇒ Object
23
24
25
26
|
# File 'lib/bunto-compose/file_mover.rb', line 23
def ensure_directory_exists
dir = File.dirname movement.to
Dir.mkdir(dir) unless Dir.exist?(dir)
end
|
#move ⇒ Object
13
14
15
16
17
|
# File 'lib/bunto-compose/file_mover.rb', line 13
def move
validate_source
ensure_directory_exists
move_file
end
|
#move_file ⇒ Object
28
29
30
31
|
# File 'lib/bunto-compose/file_mover.rb', line 28
def move_file
FileUtils.mv(movement.from, movement.to)
puts "#{resource_type.capitalize} #{movement.from} was moved to #{movement.to}"
end
|
#resource_type ⇒ Object
9
10
11
|
# File 'lib/bunto-compose/file_mover.rb', line 9
def resource_type
'file'
end
|
#validate_source ⇒ Object
19
20
21
|
# File 'lib/bunto-compose/file_mover.rb', line 19
def validate_source
raise ArgumentError.new("There was no #{resource_type} found at '#{movement.from}'.") unless File.exist? movement.from
end
|