Class: Guard::Copy
- Inherits:
-
Plugin
- Object
- Plugin
- Guard::Copy
- Defined in:
- lib/guard/copy.rb,
lib/guard/copy/target.rb
Defined Under Namespace
Classes: Target
Instance Attribute Summary collapse
-
#targets ⇒ Object
readonly
Returns the value of attribute targets.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Copy
constructor
Initializes a Guard plugin.
-
#run_all ⇒ Object
Called when just ‘enter` is pressed This method should be principally used for long action like running all specs/tests/…
-
#run_on_changes(paths) ⇒ Object
Called on file(s) modifications that the Guard watches.
-
#run_on_removals(paths) ⇒ Object
Called on file(s) deletions that the Guard watches.
-
#start ⇒ Object
Call once when Guard starts.
Constructor Details
#initialize(options = {}) ⇒ Copy
Initializes a Guard plugin. Don’t do any work here, especially as Guard plugins get initialized even if they are not in an active group!
23 24 25 26 27 |
# File 'lib/guard/copy.rb', line 23 def initialize( = {}) inject_watchers() super @targets = Array([:to]).map { |to| Target.new(to, ) } end |
Instance Attribute Details
#targets ⇒ Object (readonly)
Returns the value of attribute targets.
10 11 12 |
# File 'lib/guard/copy.rb', line 10 def targets @targets end |
Instance Method Details
#run_all ⇒ Object
Called when just ‘enter` is pressed This method should be principally used for long action like running all specs/tests/…
47 48 49 |
# File 'lib/guard/copy.rb', line 47 def run_all run_on_changes(Watcher.match_files(self, Dir.glob("**/*.*"))) end |
#run_on_changes(paths) ⇒ Object
Called on file(s) modifications that the Guard watches.
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/guard/copy.rb', line 54 def run_on_changes(paths) validate_at_least_one_target('copy') with_all_target_paths(paths) do |from_path, to_path| to_dir = File.dirname(to_path) if !File.directory?(to_dir) && [:mkpath] UI.info("creating directory #{to_dir}") if [:verbose] FileUtils.mkpath(to_dir) end validate_to_path(to_path) UI.info("copying to #{to_path}") if [:verbose] copy(from_path, to_path) end end |
#run_on_removals(paths) ⇒ Object
Called on file(s) deletions that the Guard watches.
71 72 73 74 75 76 77 78 79 |
# File 'lib/guard/copy.rb', line 71 def run_on_removals(paths) return unless [:delete] validate_at_least_one_target('delete') with_all_target_paths(paths) do |_, to_path| validate_to_file(to_path) UI.info("deleting #{to_path}") if [:verbose] FileUtils.rm(to_path) end end |
#start ⇒ Object
Call once when Guard starts. Please override initialize method to init stuff.
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/guard/copy.rb', line 31 def start validate_presence_of(:from) validate_from_is_directory validate_presence_of(:to) validate_to_patterns_are_not_absolute validate_to_does_not_start_with_from resolve_targets! validate_no_targets_are_files display_target_paths run_all if [:run_at_start] end |