Class: Katello::Hostgroup::ContentFacet

Inherits:
Model
  • Object
show all
Includes:
Facets::HostgroupFacet
Defined in:
app/models/katello/hostgroup/content_facet.rb

Instance Method Summary collapse

Methods inherited from Model

#destroy!

Instance Method Details

#content_viewObject

Object getters for backward compatibility These check for pending values first, then fall back to the CVEnv association



57
58
59
60
61
62
63
64
# File 'app/models/katello/hostgroup/content_facet.rb', line 57

def content_view
  cv_id = content_view_id
  return nil if cv_id.nil?
  return content_view_environment&.content_view if content_view_environment&.content_view_id == cv_id

  # If pending value differs from CVEnv, look it up
  ::Katello::ContentView.find_by(id: cv_id)
end

#content_view=(value) ⇒ Object

Object setters for backward compatibility



76
77
78
# File 'app/models/katello/hostgroup/content_facet.rb', line 76

def content_view=(value)
  self.content_view_id = value&.id
end

#content_view_environment=(cve) ⇒ Object

Override the content_view_environment setter to always clear pending variables when the association is assigned (either to a CVEnv or to nil)



86
87
88
89
# File 'app/models/katello/hostgroup/content_facet.rb', line 86

def content_view_environment=(cve)
  super(cve)
  clear_pending_variables
end

#content_view_idObject

Virtual attributes for API compatibility These provide backward compatibility for the deprecated content_view_id and lifecycle_environment_id attributes. Since we now use a single content_view_environment_id relationship, we need to ensure both values are provided together before we can look up the corresponding ContentViewEnvironment.

The pending variables (@pending_content_view_id, @pending_lifecycle_environment_id) serve as a temporary holding place when the API sends these values separately (e.g., in different order or in a single hash). Once both values are set, assign_single_environment() attempts to find the matching ContentViewEnvironment and assign it, then clears the pending variables.



27
28
29
30
31
32
33
# File 'app/models/katello/hostgroup/content_facet.rb', line 27

def content_view_id
  if instance_variable_defined?(:@pending_content_view_id)
    @pending_content_view_id
  else
    content_view_environment&.content_view_id
  end
end

#content_view_id=(value) ⇒ Object



35
36
37
38
39
# File 'app/models/katello/hostgroup/content_facet.rb', line 35

def content_view_id=(value)
  # Store in pending variable and attempt to resolve to a ContentViewEnvironment
  @pending_content_view_id = value
  assign_cv_env_from_pending
end

#lifecycle_environmentObject



66
67
68
69
70
71
72
73
# File 'app/models/katello/hostgroup/content_facet.rb', line 66

def lifecycle_environment
  lce_id = lifecycle_environment_id
  return nil if lce_id.nil?
  return content_view_environment&.lifecycle_environment if content_view_environment&.environment_id == lce_id

  # If pending value differs from CVEnv, look it up
  ::Katello::KTEnvironment.find_by(id: lce_id)
end

#lifecycle_environment=(value) ⇒ Object



80
81
82
# File 'app/models/katello/hostgroup/content_facet.rb', line 80

def lifecycle_environment=(value)
  self.lifecycle_environment_id = value&.id
end

#lifecycle_environment_idObject



41
42
43
44
45
46
47
# File 'app/models/katello/hostgroup/content_facet.rb', line 41

def lifecycle_environment_id
  if instance_variable_defined?(:@pending_lifecycle_environment_id)
    @pending_lifecycle_environment_id
  else
    content_view_environment&.environment_id
  end
end

#lifecycle_environment_id=(value) ⇒ Object



49
50
51
52
53
# File 'app/models/katello/hostgroup/content_facet.rb', line 49

def lifecycle_environment_id=(value)
  # Store in pending variable and attempt to resolve to a ContentViewEnvironment
  @pending_lifecycle_environment_id = value
  assign_cv_env_from_pending
end