Class: TrakFlow::Models::Dependency
- Inherits:
-
Object
- Object
- TrakFlow::Models::Dependency
- Defined in:
- lib/trak_flow/models/dependency.rb
Overview
Represents a dependency relationship between two issues Types:
- blocks: Hard dependency - target cannot proceed until source is closed
- related: Soft link - informational only
- parent-child: Hierarchical relationship
- discovered-from: Traceability link to origin
Constant Summary collapse
- VALID_TYPES =
TrakFlow::DEPENDENCY_TYPES
- BLOCKING_TYPES =
Blocking dependency types affect ready-work calculations
%w[blocks parent-child].freeze
Instance Attribute Summary collapse
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#id ⇒ Object
Returns the value of attribute id.
-
#source_id ⇒ Object
Returns the value of attribute source_id.
-
#target_id ⇒ Object
Returns the value of attribute target_id.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #blocking? ⇒ Boolean
- #blocks? ⇒ Boolean
- #discovered_from? ⇒ Boolean
- #errors ⇒ Object
-
#initialize(attrs = {}) ⇒ Dependency
constructor
A new instance of Dependency.
- #parent_child? ⇒ Boolean
- #related? ⇒ Boolean
- #to_h ⇒ Object
- #to_json(*args) ⇒ Object
- #valid? ⇒ Boolean
- #validate! ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ Dependency
Returns a new instance of Dependency.
19 20 21 22 23 24 25 |
# File 'lib/trak_flow/models/dependency.rb', line 19 def initialize(attrs = {}) @id = attrs[:id] || SecureRandom.uuid @source_id = attrs[:source_id] @target_id = attrs[:target_id] @type = attrs[:type] || "blocks" @created_at = attrs[:created_at] || Time.now.utc end |
Instance Attribute Details
#created_at ⇒ Object
Returns the value of attribute created_at.
12 13 14 |
# File 'lib/trak_flow/models/dependency.rb', line 12 def created_at @created_at end |
#id ⇒ Object
Returns the value of attribute id.
12 13 14 |
# File 'lib/trak_flow/models/dependency.rb', line 12 def id @id end |
#source_id ⇒ Object
Returns the value of attribute source_id.
12 13 14 |
# File 'lib/trak_flow/models/dependency.rb', line 12 def source_id @source_id end |
#target_id ⇒ Object
Returns the value of attribute target_id.
12 13 14 |
# File 'lib/trak_flow/models/dependency.rb', line 12 def target_id @target_id end |
#type ⇒ Object
Returns the value of attribute type.
12 13 14 |
# File 'lib/trak_flow/models/dependency.rb', line 12 def type @type end |
Class Method Details
.from_hash(hash) ⇒ Object
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/trak_flow/models/dependency.rb', line 79 def from_hash(hash) hash = hash.transform_keys(&:to_sym) new( id: hash[:id], source_id: hash[:source_id], target_id: hash[:target_id], type: hash[:type], created_at: TimeParser.parse(hash[:created_at]) ) end |
.from_json(json_string) ⇒ Object
90 91 92 |
# File 'lib/trak_flow/models/dependency.rb', line 90 def from_json(json_string) from_hash(Oj.load(json_string, mode: :compat, symbol_keys: true)) end |
Instance Method Details
#blocking? ⇒ Boolean
44 45 46 |
# File 'lib/trak_flow/models/dependency.rb', line 44 def blocking? BLOCKING_TYPES.include?(type) end |
#blocks? ⇒ Boolean
48 49 50 |
# File 'lib/trak_flow/models/dependency.rb', line 48 def blocks? type == "blocks" end |
#discovered_from? ⇒ Boolean
60 61 62 |
# File 'lib/trak_flow/models/dependency.rb', line 60 def discovered_from? type == "discovered-from" end |
#errors ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/trak_flow/models/dependency.rb', line 31 def errors errs = [] errs << "Source ID is required" if source_id.nil? || source_id.strip.empty? errs << "Target ID is required" if target_id.nil? || target_id.strip.empty? errs << "Invalid type: #{type}" unless VALID_TYPES.include?(type) errs << "Self-referential dependency not allowed" if source_id == target_id errs end |
#parent_child? ⇒ Boolean
52 53 54 |
# File 'lib/trak_flow/models/dependency.rb', line 52 def parent_child? type == "parent-child" end |
#related? ⇒ Boolean
56 57 58 |
# File 'lib/trak_flow/models/dependency.rb', line 56 def type == "related" end |
#to_h ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/trak_flow/models/dependency.rb', line 64 def to_h { id: id, source_id: source_id, target_id: target_id, type: type, created_at: created_at&.iso8601 }.compact end |
#to_json(*args) ⇒ Object
74 75 76 |
# File 'lib/trak_flow/models/dependency.rb', line 74 def to_json(*args) Oj.dump(to_h, mode: :compat) end |
#valid? ⇒ Boolean
27 28 29 |
# File 'lib/trak_flow/models/dependency.rb', line 27 def valid? errors.empty? end |
#validate! ⇒ Object
40 41 42 |
# File 'lib/trak_flow/models/dependency.rb', line 40 def validate! raise ValidationError, errors.join(", ") unless valid? end |