Class: ForeignInputSet

Inherits:
ApplicationRecord
  • Object
show all
Includes:
Exportable
Defined in:
app/models/foreign_input_set.rb

Defined Under Namespace

Classes: CircularDependencyError

Instance Method Summary collapse

Instance Method Details

#excluded_namesObject



36
37
38
# File 'app/models/foreign_input_set.rb', line 36

def excluded_names
  comma_separated_names(self.exclude)
end

#included_namesObject



32
33
34
# File 'app/models/foreign_input_set.rb', line 32

def included_names
  comma_separated_names(self.include)
end

#inputs(templates_stack = []) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/models/foreign_input_set.rb', line 17

def inputs(templates_stack = [])
  return [] unless target_template

  if templates_stack.include?(target_template) || template&.id == target_template&.id
    raise CircularDependencyError.new(N_("Circular dependency detected in foreign input set '%{template}' -> '%{target_template}'. Templates stack: %{templates_stack}"),
      :template => template.name, :target_template => target_template.name, :templates_stack => templates_stack.map(&:name).inspect)
  end
  inputs = target_template.template_inputs_with_foreign(templates_stack + [target_template])
  unless self.include_all?
    inputs = inputs.select { |input| included_names.include?(input.name) }
  end
  inputs = inputs.reject { |input| excluded_names.include?(input.name) }
  return inputs
end