Class: Ace::Support::Nav::Models::ProtocolSource

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/support/nav/models/protocol_source.rb

Overview

Represents a source registration for a protocol

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, type:, path:, priority:, description: nil, origin: nil, config_file: nil, config_dir: nil, config: nil) ⇒ ProtocolSource

Returns a new instance of ProtocolSource.



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ace/support/nav/models/protocol_source.rb', line 11

def initialize(name:, type:, path:, priority:, description: nil, origin: nil, config_file: nil, config_dir: nil, config: nil)
  @name = name
  @type = type
  @path = path
  @priority = priority
  @description = description
  @origin = origin
  @config_file = config_file
  @config_dir = config_dir
  @config = config
  @alias_name = "@#{name}"
end

Instance Attribute Details

#alias_nameObject (readonly)

Returns the value of attribute alias_name.



9
10
11
# File 'lib/ace/support/nav/models/protocol_source.rb', line 9

def alias_name
  @alias_name
end

#configObject (readonly)

Returns the value of attribute config.



9
10
11
# File 'lib/ace/support/nav/models/protocol_source.rb', line 9

def config
  @config
end

#config_dirObject (readonly)

Returns the value of attribute config_dir.



9
10
11
# File 'lib/ace/support/nav/models/protocol_source.rb', line 9

def config_dir
  @config_dir
end

#config_fileObject (readonly)

Returns the value of attribute config_file.



9
10
11
# File 'lib/ace/support/nav/models/protocol_source.rb', line 9

def config_file
  @config_file
end

#descriptionObject (readonly)

Returns the value of attribute description.



9
10
11
# File 'lib/ace/support/nav/models/protocol_source.rb', line 9

def description
  @description
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/ace/support/nav/models/protocol_source.rb', line 9

def name
  @name
end

#originObject (readonly)

Returns the value of attribute origin.



9
10
11
# File 'lib/ace/support/nav/models/protocol_source.rb', line 9

def origin
  @origin
end

#pathObject (readonly)

Returns the value of attribute path.



9
10
11
# File 'lib/ace/support/nav/models/protocol_source.rb', line 9

def path
  @path
end

#priorityObject (readonly)

Returns the value of attribute priority.



9
10
11
# File 'lib/ace/support/nav/models/protocol_source.rb', line 9

def priority
  @priority
end

#typeObject (readonly)

Returns the value of attribute type.



9
10
11
# File 'lib/ace/support/nav/models/protocol_source.rb', line 9

def type
  @type
end

Instance Method Details

#exists?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/ace/support/nav/models/protocol_source.rb', line 65

def exists?
  Dir.exist?(full_path)
end

#full_pathObject

Get the full path for this source



25
26
27
28
29
30
31
32
33
34
35
36
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
# File 'lib/ace/support/nav/models/protocol_source.rb', line 25

def full_path
  case @type
  when "gem"
    # For gem type, resolve through RubyGems
    require "rubygems"
    begin
      spec = Gem::Specification.find_by_name(@name)
      gem_dir = spec.gem_dir

      # Get relative path from config, or use default
      relative = @config&.dig("relative_path") || "handbook/workflow-instructions"

      File.join(gem_dir, relative)
    rescue Gem::LoadError => e
      # Gem not found, return a placeholder path
      warn "Gem '#{@name}' not found: #{e.message}" if ENV["VERBOSE"]
      "/gem-not-found/#{@name}"
    end
  else
    # Original path resolution logic for directory/path types
    return path if path&.start_with?("/")

    if config_dir && path
      # Resolve relative paths from project root (parent of .ace directory)
      project_dir = find_project_root(config_dir)
      if project_dir
        File.expand_path(File.join(project_dir, path))
      else
        File.expand_path(path)
      end
    elsif path
      # Fallback to expand from current directory
      File.expand_path(path)
    else
      # No path specified
      "/no-path-specified"
    end
  end
end

#to_hObject



69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/ace/support/nav/models/protocol_source.rb', line 69

def to_h
  {
    name: name,
    type: type,
    path: path,
    full_path: full_path,
    priority: priority,
    description: description,
    origin: origin,
    exists: exists?
  }
end

#to_sObject



82
83
84
# File 'lib/ace/support/nav/models/protocol_source.rb', line 82

def to_s
  "#{name} (#{type}): #{full_path}"
end