Class: Refinement::AnnotatedTarget
- Inherits:
-
Object
- Object
- Refinement::AnnotatedTarget
- Defined in:
- lib/refinement/annotated_target.rb
Overview
A target, annotated with any changes
Instance Attribute Summary collapse
-
#depended_upon_by ⇒ Array<AnnotatedTarget>
readonly
The list of annotated targets that depend upon this target.
-
#dependencies ⇒ Array<AnnotatedTarget>
readonly
The list of annotated targets this target depends upon.
-
#xcode_target ⇒ Xcodeproj::Project::AbstactTarget
readonly
The target in an Xcode project.
Instance Method Summary collapse
-
#change_reason(level:) ⇒ Boolean
Whether the target has changed, at the given change level.
-
#initialize(target:, change_reason:, dependencies: []) ⇒ AnnotatedTarget
constructor
A new instance of AnnotatedTarget.
Constructor Details
#initialize(target:, change_reason:, dependencies: []) ⇒ AnnotatedTarget
Returns a new instance of AnnotatedTarget.
13 14 15 16 17 18 19 20 21 |
# File 'lib/refinement/annotated_target.rb', line 13 def initialize(target:, change_reason:, dependencies: []) @xcode_target = target @direct_change_reason = change_reason @dependencies = dependencies dependencies.each do |dependency| dependency.depended_upon_by << self end @depended_upon_by = [] end |
Instance Attribute Details
#depended_upon_by ⇒ Array<AnnotatedTarget> (readonly)
Returns the list of annotated targets that depend upon this target.
74 75 76 |
# File 'lib/refinement/annotated_target.rb', line 74 def depended_upon_by @depended_upon_by end |
#dependencies ⇒ Array<AnnotatedTarget> (readonly)
Returns the list of annotated targets this target depends upon.
72 73 74 |
# File 'lib/refinement/annotated_target.rb', line 72 def dependencies @dependencies end |
#xcode_target ⇒ Xcodeproj::Project::AbstactTarget (readonly)
Returns the target in an Xcode project.
7 8 9 |
# File 'lib/refinement/annotated_target.rb', line 7 def xcode_target @xcode_target end |
Instance Method Details
#change_reason(level:) ⇒ Boolean
Returns whether the target has changed, at the given change level.
37 38 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 |
# File 'lib/refinement/annotated_target.rb', line 37 def change_reason(level:) @change_reason ||= {} # need to use this form for memoization, as opposed to ||=, # since this will (often) be nil and it makes a significant performance difference return @change_reason[level] if @change_reason.key?(level) @change_reason[level] = case level when :itself direct_change_reason when :full_transitive direct_change_reason || Refinement.map_find(dependencies) do |dependency| next unless (dependency_change_reason = dependency.change_reason(level: level)) "dependency #{dependency} changed because #{dependency_change_reason}" end when proc { |symbol, int| (symbol == :at_most_n_away) && int.is_a?(Integer) } distance_from_target = level.last raise ArgumentError, "level must be positive, not #{distance_from_target}" if distance_from_target.negative? change_reason = direct_change_reason if distance_from_target.positive? change_reason ||= Refinement.map_find(dependencies) do |dependency| next unless (dependency_change_reason = dependency.change_reason(level: [:at_most_n_away, level.last.pred])) "dependency #{dependency} changed because #{dependency_change_reason}" end end change_reason else raise Error, "No known change level #{level.inspect}, only #{CHANGE_LEVELS.inspect} are known" end end |