Class: ConfigmonkeyCli::Application::ManifestAction::Copy
- Inherits:
-
Base
- Object
- Base
- ConfigmonkeyCli::Application::ManifestAction::Copy
show all
- Defined in:
- lib/configmonkey_cli/application/manifest_actions/copy.rb
Instance Attribute Summary
Attributes inherited from Base
#app, #args, #manifest, #opts, #thor
Instance Method Summary
collapse
Methods inherited from Base
#args_and_opts, #exists?, #expand_dst, #expand_src, #initialize, #rel, #to_s
Instance Method Details
44
45
46
|
# File 'lib/configmonkey_cli/application/manifest_actions/copy.rb', line 44
def _perform_directory(source, destination, opts)
thor.directory(source, destination, opts)
end
|
48
49
50
|
# File 'lib/configmonkey_cli/application/manifest_actions/copy.rb', line 48
def _perform_file(source, destination, opts)
thor.copy_file(source, destination, opts)
end
|
#destructive ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/configmonkey_cli/application/manifest_actions/copy.rb', line 23
def destructive
absolute_source = File.join(thor.source_paths[0], @source)
has_changed = !File.exist?(@destination)
if @opts[:after_change] && File.exist?(@destination)
has_changed = File.binread(absolute_source) != File.binread(@destination)
end
if FileTest.directory?(absolute_source)
_perform_directory(@source, @destination, @opts)
else
_perform_file(@source, @destination, @opts)
if @opts[:chmod] && File.exist?(absolute_source) && File.exist?(@destination)
mode = @opts[:chmod] == true ? File.stat(absolute_source).mode - 0100000 : @opts[:chmod]
thor.chmod(@destination, mode) unless mode == File.stat(@destination).mode - 0100000
end
end
@opts[:after_change].call if has_changed && @opts[:after_change]
end
|
#init(hargs_and_opts = {}) ⇒ Object
5
6
7
|
# File 'lib/configmonkey_cli/application/manifest_actions/copy.rb', line 5
def init hargs_and_opts = {}
@args, @opts = args_and_opts(hargs_and_opts)
end
|
#prepare ⇒ Object
9
10
11
12
13
|
# File 'lib/configmonkey_cli/application/manifest_actions/copy.rb', line 9
def prepare
@opts[:force] = app.opts[:default_yes]
@source = @args[0]
@destination = expand_dst(@args[1])
end
|
#simulate ⇒ Object
15
16
17
18
19
20
21
|
# File 'lib/configmonkey_cli/application/manifest_actions/copy.rb', line 15
def simulate
if thor.options[:pretend]
destructive
else
status :fake, :black, rel(@destination)
end
end
|