Class: Lutaml::Cli::ResourceRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/cli/resource_registry.rb

Overview

ResourceRegistry manages element type configurations for CLI commands

This registry provides a centralized definition of UML element types and their corresponding repository methods and presenters. It enables extensibility by allowing new element types to be easily added.

Examples:

Get configuration for a type

config = ResourceRegistry.config_for(:class)
classes = repository.send(config[:list_method])

List all available types

ResourceRegistry.types # => [:package, :class, :diagram, ...]

Constant Summary collapse

TYPES =

Element type configurations

Each type defines:

  • list_method: Repository method to list all elements of this type

  • find_method: Repository method to find a single element

  • presenter: Presenter class name for formatting output

  • icon: Display icon for this element type

  • description: Human-readable description

{
  package: {
    list_method: :list_packages,
    find_method: :find_package,
    presenter: :PackagePresenter,
    icon: "📦",
    description: "Package container",
  },
  class: {
    list_method: :all_classes,
    find_method: :find_class,
    presenter: :ClassPresenter,
    icon: "📋",
    description: "UML Class",
  },
  diagram: {
    list_method: :all_diagrams,
    find_method: :find_diagram,
    presenter: :DiagramPresenter,
    icon: "🖼️",
    description: "UML Diagram",
  },
  attribute: {
    list_method: :all_attributes,
    find_method: :find_attribute,
    presenter: :AttributePresenter,
    icon: "🔹",
    description: "Class attribute",
  },
  association: {
    list_method: :all_associations,
    find_method: :find_association,
    presenter: :AssociationPresenter,
    icon: "🔗",
    description: "Class association",
  },
  enum: {
    list_method: :all_enums,
    find_method: :find_enum,
    presenter: :EnumPresenter,
    icon: "🔢",
    description: "Enumeration",
  },
  datatype: {
    list_method: :all_data_types,
    find_method: :find_data_type,
    presenter: :DataTypePresenter,
    icon: "📊",
    description: "Data type",
  },
}.freeze

Class Method Summary collapse

Class Method Details

.config_for(type) ⇒ Hash?

Get configuration for a specific type

Parameters:

  • type (Symbol, String)

    Element type name

Returns:

  • (Hash, nil)

    Type configuration or nil if not found



89
90
91
# File 'lib/lutaml/cli/resource_registry.rb', line 89

def self.config_for(type)
  TYPES[type.to_sym]
end

.description_for(type) ⇒ String

Get description for a type

Parameters:

  • type (Symbol, String)

    Element type name

Returns:

  • (String)

    Description or empty string if not found



114
115
116
117
# File 'lib/lutaml/cli/resource_registry.rb', line 114

def self.description_for(type)
  config = config_for(type)
  config ? config[:description] : ""
end

.icon_for(type) ⇒ String

Get icon for a type

Parameters:

  • type (Symbol, String)

    Element type name

Returns:

  • (String)

    Icon string or empty string if not found



105
106
107
108
# File 'lib/lutaml/cli/resource_registry.rb', line 105

def self.icon_for(type)
  config = config_for(type)
  config ? config[:icon] : ""
end

.type_descriptionsHash<Symbol, String>

Get all types with their descriptions

Returns:

  • (Hash<Symbol, String>)

    Map of type to description



122
123
124
# File 'lib/lutaml/cli/resource_registry.rb', line 122

def self.type_descriptions
  TYPES.transform_values { |config| config[:description] }
end

.type_registered?(type) ⇒ Boolean

Check if a type is registered

Parameters:

  • type (Symbol, String)

    Element type name

Returns:

  • (Boolean)

    True if type is registered



97
98
99
# File 'lib/lutaml/cli/resource_registry.rb', line 97

def self.type_registered?(type)
  TYPES.key?(type.to_sym)
end

.typesArray<Symbol>

Get all registered element types

Returns:

  • (Array<Symbol>)

    List of type names



81
82
83
# File 'lib/lutaml/cli/resource_registry.rb', line 81

def self.types
  TYPES.keys
end