Class: MxxRu::TargetState
- Inherits:
-
Object
- Object
- MxxRu::TargetState
- Defined in:
- lib/mxx_ru/abstract_target.rb
Overview
Target status description.
Constant Summary collapse
- ABSENT =
Target is absent or rebuild is required.
0
- REBUILT =
Target was rebuilt.
1
- EXISTS =
Target exists and up-to-date.
2
Instance Attribute Summary collapse
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Class Method Summary collapse
-
.detect(name, depends) ⇒ Object
Detect target status.
-
.make_absent ⇒ Object
Creates and returns objects of state ABSENT.
-
.rebuilding_needed?(*statuses) ⇒ Boolean
Checks collection of statuses.
Instance Method Summary collapse
-
#initialize(a_state = ABSENT) ⇒ TargetState
constructor
A new instance of TargetState.
Constructor Details
#initialize(a_state = ABSENT) ⇒ TargetState
Returns a new instance of TargetState.
49 50 51 |
# File 'lib/mxx_ru/abstract_target.rb', line 49 def initialize( a_state = ABSENT ) @state = a_state end |
Instance Attribute Details
#state ⇒ Object (readonly)
Returns the value of attribute state.
47 48 49 |
# File 'lib/mxx_ru/abstract_target.rb', line 47 def state @state end |
Class Method Details
.detect(name, depends) ⇒ Object
Detect target status. TargetState object returned.
- name
-
Target name.
- depends
-
Dependencies list. Array of String.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/mxx_ru/abstract_target.rb', line 58 def TargetState.detect( name, depends ) state = ABSENT # In dry-run mode we always return that target is absent. if !MxxRu::Util::Mode.instance.is_dry_run if FileTest.exists?( name ) # It's necessary to detect time of target and it's dependencies. target_mtime = File.mtime( name ) if nil != depends.find { |d| if !FileTest.exists?( d ) raise MxxRu::MissingDependFileEx.new( d, name ) end depend_mtime = File.mtime( d ) target_mtime < depend_mtime } # More young dependency found. state = REBUILT else # Target is up-to-date. state = EXISTS end end end return TargetState.new( state ) end |
.make_absent ⇒ Object
Creates and returns objects of state ABSENT
Since v.1.4.4
109 110 111 |
# File 'lib/mxx_ru/abstract_target.rb', line 109 def TargetState.make_absent TargetState.new( ABSENT ) end |
.rebuilding_needed?(*statuses) ⇒ Boolean
Checks collection of statuses.
Returns true if at least one of statuses have value REBUILT or ABSENT.
Typical usage is:
subprojects_status = build_subprojects
self_files_status = build_self_files
if TargetState.rebuilding_needed?(
subprojects_status, self_files_status )
do_rebuild
end
Since v.1.4.4
101 102 103 |
# File 'lib/mxx_ru/abstract_target.rb', line 101 def TargetState.rebuilding_needed?( *statuses ) nil != statuses.find { |s| EXISTS != s.state } end |