Class: 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(watchers = [], options = {}) ⇒ Copy
constructor
Initialize a Guard.
-
#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(watchers = [], options = {}) ⇒ Copy
Initialize a Guard.
15 16 17 18 19 20 21 22 23 |
# File 'lib/guard/copy.rb', line 15 def initialize(watchers = [], = {}) super if watchers.empty? watchers << ::Guard::Watcher.new(%r{^#{[:from]}/.*$}) else watchers.each { |w| normalize_watcher(w, [:from]) } end @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/…
43 44 45 |
# File 'lib/guard/copy.rb', line 43 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.
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/guard/copy.rb', line 50 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.
67 68 69 70 71 72 73 74 75 |
# File 'lib/guard/copy.rb', line 67 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.
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/guard/copy.rb', line 27 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 |