Class: Worktrees::Models::FeatureWorktree
- Inherits:
-
Object
- Object
- Worktrees::Models::FeatureWorktree
- Defined in:
- lib/worktrees/models/feature_worktree.rb
Constant Summary collapse
- NAME_PATTERN =
/^[0-9]{3}-[a-z0-9-]{1,40}$/.freeze
- RESERVED_NAMES =
%w[main master].freeze
Instance Attribute Summary collapse
-
#base_ref ⇒ Object
readonly
Returns the value of attribute base_ref.
-
#branch ⇒ Object
readonly
Returns the value of attribute branch.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#repository_path ⇒ Object
readonly
Returns the value of attribute repository_path.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
Instance Method Summary collapse
- #active? ⇒ Boolean
- #dirty? ⇒ Boolean
-
#initialize(name:, path:, branch:, base_ref:, status:, created_at:, repository_path:) ⇒ FeatureWorktree
constructor
A new instance of FeatureWorktree.
- #to_h ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(name:, path:, branch:, base_ref:, status:, created_at:, repository_path:) ⇒ FeatureWorktree
Returns a new instance of FeatureWorktree.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/worktrees/models/feature_worktree.rb', line 13 def initialize(name:, path:, branch:, base_ref:, status:, created_at:, repository_path:) @name = name @path = path @branch = branch @base_ref = base_ref @status = status @created_at = created_at @repository_path = repository_path validate! end |
Instance Attribute Details
#base_ref ⇒ Object (readonly)
Returns the value of attribute base_ref.
11 12 13 |
# File 'lib/worktrees/models/feature_worktree.rb', line 11 def base_ref @base_ref end |
#branch ⇒ Object (readonly)
Returns the value of attribute branch.
11 12 13 |
# File 'lib/worktrees/models/feature_worktree.rb', line 11 def branch @branch end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
11 12 13 |
# File 'lib/worktrees/models/feature_worktree.rb', line 11 def created_at @created_at end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/worktrees/models/feature_worktree.rb', line 11 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
11 12 13 |
# File 'lib/worktrees/models/feature_worktree.rb', line 11 def path @path end |
#repository_path ⇒ Object (readonly)
Returns the value of attribute repository_path.
11 12 13 |
# File 'lib/worktrees/models/feature_worktree.rb', line 11 def repository_path @repository_path end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
11 12 13 |
# File 'lib/worktrees/models/feature_worktree.rb', line 11 def status @status end |
Class Method Details
.validate_name(name) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/worktrees/models/feature_worktree.rb', line 60 def self.validate_name(name) return false unless name.is_a?(String) return false unless name.match?(NAME_PATTERN) # Extract feature part after NNN- feature_part = name.split('-', 2)[1] return false if feature_part.nil? # Check for reserved names !RESERVED_NAMES.include?(feature_part.downcase) end |
Instance Method Details
#active? ⇒ Boolean
39 40 41 |
# File 'lib/worktrees/models/feature_worktree.rb', line 39 def active? @status == :active end |
#dirty? ⇒ Boolean
43 44 45 |
# File 'lib/worktrees/models/feature_worktree.rb', line 43 def dirty? @status == :dirty end |
#to_h ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/worktrees/models/feature_worktree.rb', line 47 def to_h { name: @name, path: @path, branch: @branch, base_ref: @base_ref, status: @status, created_at: @created_at, repository_path: @repository_path, active: active? } end |
#valid? ⇒ Boolean
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/worktrees/models/feature_worktree.rb', line 25 def valid? return false unless @name.is_a?(String) && @name.match?(NAME_PATTERN) feature_part = @name.split('-', 2)[1] return false if feature_part.nil? return false if RESERVED_NAMES.include?(feature_part.downcase) return false if @path.nil? || @path.empty? return false if @branch.nil? || @branch.empty? return false if @base_ref.nil? || @base_ref.empty? true end |