Class: Command
- Inherits:
-
Object
- Object
- Command
- Defined in:
- lib/command.rb
Instance Attribute Summary collapse
-
#fn ⇒ Object
Returns the value of attribute fn.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
-
#call ⇒ Object
Execute the command if needed (dependency files changed).
-
#call_now ⇒ Object
Force call the command, even if none of the files changed.
-
#initialize(name, file_deps, fn) ⇒ Command
constructor
A new instance of Command.
-
#should_run? ⇒ Boolean
Returns wheter the command should run, meaning if any of the depency files changed.
Constructor Details
#initialize(name, file_deps, fn) ⇒ Command
Returns a new instance of Command.
7 8 9 10 11 12 13 |
# File 'lib/command.rb', line 7 def initialize(name, file_deps, fn) @name = name # When one of these files changes, the command should rerun # Type: FileDep, or nil @file_deps = file_deps @fn = fn end |
Instance Attribute Details
#fn ⇒ Object
Returns the value of attribute fn.
5 6 7 |
# File 'lib/command.rb', line 5 def fn @fn end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/command.rb', line 4 def name @name end |
Instance Method Details
#call ⇒ Object
Execute the command if needed (dependency files changed)
16 17 18 19 20 |
# File 'lib/command.rb', line 16 def call if self.should_run? self.call_now() end end |
#call_now ⇒ Object
Force call the command, even if none of the files changed
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/command.rb', line 23 def call_now $file = nil $files = nil if @file_deps.type == :each @file_deps.files.each do |file_obj| $file = file_obj @fn.call() end else $files = @file_deps.files @fn.call() end end |
#should_run? ⇒ Boolean
Returns wheter the command should run, meaning if any of the depency files changed
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/command.rb', line 39 def should_run? if changed? "__BEAVER__CONFIG__", $PROGRAM_NAME # Ruby script itself changed # TODO: does not account for dependencies of the script (probably uncommon though) # Clear cache, because the config failed reset_cache unless @file_deps.nil? @file_deps.each_file do |file| $cache.files.add(@name, file) end end return true end if @file_deps.nil? return true end changed = false @file_deps.each_file do |file| if !changed && (changed? @name, file) changed = true end $cache.files.add(@name, file) end return changed end |