Class: RemoteExecutionFeature

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
FriendlyId
Defined in:
app/models/remote_execution_feature.rb

Constant Summary collapse

VALID_OPTIONS =
[:provided_inputs, :description, :host_action_button].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.feature(label) ⇒ Object



20
21
22
# File 'app/models/remote_execution_feature.rb', line 20

def self.feature(label)
  self.find_by(label: label) || raise(::Foreman::Exception.new(N_('Unknown remote execution feature %s'), label))
end

.register(label, name, options = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/models/remote_execution_feature.rb', line 24

def self.register(label, name, options = {})
  return false unless RemoteExecutionFeature.table_exists?
  options.assert_valid_keys(*VALID_OPTIONS)
  options[:host_action_button] = false unless options.key?(:host_action_button)

  feature = self.find_by(label: label)

  attributes = { :name => name, :provided_input_names => options[:provided_inputs], :description => options[:description], :host_action_button => options[:host_action_button] }
  # in case DB does not have the attribute created yet but plugin initializer registers the feature, we need to skip this attribute
  unless self.attribute_names.include?('host_action_button')
    attributes.delete(:host_action_button)
  end

  if feature.nil?
    feature = self.create!({ :label => label }.merge(attributes))
  else
    feature.attributes = attributes
    feature.save if feature.changed?
  end
  return feature
end

Instance Method Details

#provided_input_namesObject



12
13
14
# File 'app/models/remote_execution_feature.rb', line 12

def provided_input_names
  self.provided_inputs.to_s.split(',').map(&:strip)
end

#provided_input_names=(values) ⇒ Object



16
17
18
# File 'app/models/remote_execution_feature.rb', line 16

def provided_input_names=(values)
  self.provided_inputs = Array(values).join(',')
end