Class: Pangea::Entities::ModuleDefinition
- Defined in:
- lib/pangea/entities/module_definition.rb
Defined Under Namespace
Modules: Type
Instance Method Summary collapse
- #function_module? ⇒ Boolean
- #load_path ⇒ Object
- #optional_inputs ⇒ Object
- #required_inputs ⇒ Object
- #resource_module? ⇒ Boolean
- #to_documentation ⇒ Object
- #validate_inputs(provided_inputs) ⇒ Object
Instance Method Details
#function_module? ⇒ Boolean
48 49 50 |
# File 'lib/pangea/entities/module_definition.rb', line 48 def function_module? type == Type::FUNCTION || type == Type::COMPOSITE end |
#load_path ⇒ Object
52 53 54 55 56 57 |
# File 'lib/pangea/entities/module_definition.rb', line 52 def load_path return path if path return File.dirname(source) if source "modules/#{name}" end |
#optional_inputs ⇒ Object
63 64 65 |
# File 'lib/pangea/entities/module_definition.rb', line 63 def optional_inputs inputs.reject { |_, config| config[:required] }.keys end |
#required_inputs ⇒ Object
59 60 61 |
# File 'lib/pangea/entities/module_definition.rb', line 59 def required_inputs inputs.select { |_, config| config[:required] }.keys end |
#resource_module? ⇒ Boolean
44 45 46 |
# File 'lib/pangea/entities/module_definition.rb', line 44 def resource_module? type == Type::RESOURCE || type == Type::COMPOSITE end |
#to_documentation ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/pangea/entities/module_definition.rb', line 93 def to_documentation doc = ["# Module: #{name}"] doc << "Version: #{version}" if version doc << "\n#{description}" if description doc << "\nAuthor: #{}" if if inputs.any? doc << "\n## Inputs" inputs.each do |name, config| required = config[:required] ? " (required)" : "" doc << "- `#{name}`#{required}: #{config[:description] || 'No description'}" doc << " - Type: #{config[:type]}" if config[:type] doc << " - Default: #{config[:default]}" if config[:default] end end if outputs.any? doc << "\n## Outputs" outputs.each do |name, config| doc << "- `#{name}`: #{config[:description] || 'No description'}" end end doc.join("\n") end |
#validate_inputs(provided_inputs) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/pangea/entities/module_definition.rb', line 67 def validate_inputs(provided_inputs) errors = [] provided = provided_inputs.keys.map(&:to_sym) required_inputs.each do |input| unless provided.include?(input) errors << "Missing required input: #{input}" end end provided.each do |input| unless inputs.key?(input) errors << "Unknown input: #{input}" end end provided_inputs.each do |key, value| if inputs[key.to_sym] && inputs[key.to_sym][:type] expected_type = inputs[key.to_sym][:type] end end raise ValidationError, errors.join(", ") unless errors.empty? true end |