Module: Legate::Tool::MetadataDsl::ClassMethods
- Defined in:
- lib/legate/tool/metadata_dsl.rb
Instance Method Summary collapse
-
#effective_tool_name ⇒ Object
Get the final tool name with priority: 1.
-
#inferred_name ⇒ Object
Get the inferred name (logic unchanged).
-
#parameter(name, options = {}) ⇒ Object
DSL method for defining a parameter.
-
#tool_description(text) ⇒ Object
DSL method for setting description.
-
#tool_metadata ⇒ Object
Retrieve consolidated metadata, preferring DSL values but falling back to define_metadata values.
Instance Method Details
#effective_tool_name ⇒ Object
Get the final tool name with priority:
-
DSL’s explicit_tool_name
-
define_metadata’s @tool_name
-
Inferred name
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/legate/tool/metadata_dsl.rb', line 80 def effective_tool_name initialize_dsl_storage # Ensure @explicit_tool_name exists explicit_dsl = explicit_tool_name return explicit_dsl if explicit_dsl && explicit_dsl != :'' # Check define_metadata's variable if explicit DSL name wasn't set # Use instance_variable_get as @tool_name is not directly accessible via reader here if instance_variable_defined?(:@tool_name) explicit_old = instance_variable_get(:@tool_name) return explicit_old if explicit_old && explicit_old != :'' end # Fallback to inferred name inferred_name end |
#inferred_name ⇒ Object
Get the inferred name (logic unchanged)
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/legate/tool/metadata_dsl.rb', line 60 def inferred_name class_name_str = Module.instance_method(:name).bind(self).call return nil unless class_name_str && !class_name_str.empty? && class_name_str.is_a?(String) return nil if class_name_str.start_with?('#<Class:') inferred = class_name_str.split('::').last return nil if inferred.nil? || inferred.empty? inferred = inferred.dup inferred.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2') inferred.gsub!(/([a-z\d])([A-Z])/, '\1_\2') inferred.tr!('-', '_') inferred.downcase! inferred.to_sym end |
#parameter(name, options = {}) ⇒ Object
DSL method for defining a parameter
51 52 53 54 55 56 57 |
# File 'lib/legate/tool/metadata_dsl.rb', line 51 def parameter(name, = {}) initialize_dsl_storage # Ensure hash exists raise ArgumentError, 'Parameter name must be a Symbol' unless name.is_a?(Symbol) @parameters_definition[name] = @_tool_metadata_cache = nil # Invalidate cache on modification end |
#tool_description(text) ⇒ Object
DSL method for setting description
45 46 47 48 |
# File 'lib/legate/tool/metadata_dsl.rb', line 45 def tool_description(text) initialize_dsl_storage # Ensure vars exist self.description = text.to_s end |
#tool_metadata ⇒ Object
Retrieve consolidated metadata, preferring DSL values but falling back to define_metadata values. Cached for performance.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/legate/tool/metadata_dsl.rb', line 98 def @_tool_metadata_cache ||= begin initialize_dsl_storage # Ensure DSL variables exist # Get description: Prefer DSL, fallback to define_metadata's @description dsl_desc = description old_desc = instance_variable_get(:@description) if instance_variable_defined?(:@description) && dsl_desc.nil? final_desc = dsl_desc || old_desc # Get parameters: Prefer DSL, fallback to define_metadata's @parameters_definition dsl_params = parameters_definition old_params = instance_variable_get(:@parameters_definition) if instance_variable_defined?(:@parameters_definition) && (dsl_params.nil? || dsl_params.empty?) final_params = dsl_params && !dsl_params.empty? ? dsl_params : (old_params || {}) { name: effective_tool_name, description: final_desc, parameters: final_params } end end |