Class: Registration::Addon

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
src/lib/registration/addon.rb

Overview

this is a wrapper class around SUSE::Connect::Product object

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pure_addon) ⇒ Addon

the constructor

Parameters:

  • pure_addon (SUSE::Connect::Product)

    a pure add-on from the registration server


116
117
118
119
# File 'src/lib/registration/addon.rb', line 116

def initialize(pure_addon)
  @pure_addon = pure_addon
  @children = []
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children


96
97
98
# File 'src/lib/registration/addon.rb', line 96

def children
  @children
end

#depends_onObject

Returns the value of attribute depends_on


97
98
99
# File 'src/lib/registration/addon.rb', line 97

def depends_on
  @depends_on
end

#regcodeObject

Returns the value of attribute regcode


97
98
99
# File 'src/lib/registration/addon.rb', line 97

def regcode
  @regcode
end

Class Method Details

.find_all(registration) ⇒ Object

read the remote add-on from the registration server

Parameters:


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'src/lib/registration/addon.rb', line 32

def find_all(registration)
  return @cached_addons if @cached_addons
  pure_addons = registration.get_addon_list
  # get IDs of the already activated addons
  activated_addon_ids = registration.activated_products.map(&:id)

  @cached_addons = pure_addons.reduce([]) do |res, addon|
    yast_addons = create_addon_with_deps(addon)

    # mark as registered if found in the status call
    yast_addons.each do |yast_addon|
      yast_addon.registered if activated_addon_ids.include?(yast_addon.id)
    end

    res.concat(yast_addons)
  end
end

.registeredArray<Addon>

list of registered add-ons

Returns:

  • (Array<Addon>)

    registered add-ons


52
53
54
# File 'src/lib/registration/addon.rb', line 52

def registered
  @registered ||= []
end

.registered_not_installedArray<Addon>

return add-ons which are registered but not installed in the system

Returns:

  • (Array<Addon>)

    the list of add-ons


64
65
66
67
68
69
70
71
72
# File 'src/lib/registration/addon.rb', line 64

def registered_not_installed
  registered.select do |addon|
    !SwMgmt.installed_products.find do |product|
      product["name"] == addon.identifier &&
        product["version_version"] == addon.version &&
        product["arch"] == addon.arch
    end
  end
end

.selectedArray<Addon>

list of selected add-ons

Returns:

  • (Array<Addon>)

    selected add-ons


58
59
60
# File 'src/lib/registration/addon.rb', line 58

def selected
  @selected ||= []
end

Instance Method Details

#available?Boolean

is the addon available? SMT may have mirrored only some extensions, the not mirrored extensions are marked as not available

Returns:

  • (Boolean)

    true if the addon is available to register


203
204
205
206
207
# File 'src/lib/registration/addon.rb', line 203

def available?
  # explicitly check for false, undefined (nil) means it is available,
  # it's only reported by SMT
  @pure_addon.available != false
end

#beta_release?Boolean

Returns:

  • (Boolean)

162
163
164
# File 'src/lib/registration/addon.rb', line 162

def beta_release?
  release_stage == "beta"
end

#labelString

get a product printable name (long name if present, fallbacks to the short name)

Returns:

  • (String)

    label usable in UI


168
169
170
# File 'src/lib/registration/addon.rb', line 168

def label
  (friendly_name && !friendly_name.empty?) ? friendly_name : name
end

#matches_remote_product?(remote_product) ⇒ Boolean

Returns:

  • (Boolean)

216
217
218
219
220
# File 'src/lib/registration/addon.rb', line 216

def matches_remote_product?(remote_product)
  [:arch, :identifier, :version, :release_type].all? do |attr|
    send(attr) == remote_product.send(attr)
  end
end

#registeredObject

mark the add-on as registered


153
154
155
# File 'src/lib/registration/addon.rb', line 153

def registered
  Addon.registered << self unless registered?
end

#registered?Boolean

has been the add-on registered?

Returns:

  • (Boolean)

    true if the add-on has been registered


148
149
150
# File 'src/lib/registration/addon.rb', line 148

def registered?
  Addon.registered.include?(self)
end

#selectable?Boolean

can be the addon selected in UI or should it be disabled? return [Boolean] true if it should be enabled

Returns:

  • (Boolean)

174
175
176
177
178
179
180
181
182
183
184
185
# File 'src/lib/registration/addon.rb', line 174

def selectable?
  # Do not support unregister
  return false if registered?
  # Do not select not available addons
  return false if !available?
  # Do not allow to select child without selected or already registered parent
  return false if depends_on && !(depends_on.selected? || depends_on.registered?)
  # Do not allow to unselect parent if any children is selected
  return false if children.any?(&:selected?)

  true
end

#selectedObject

select the add-on


128
129
130
# File 'src/lib/registration/addon.rb', line 128

def selected
  Addon.selected << self unless selected?
end

#selected?Boolean

is the add-on selected

Returns:

  • (Boolean)

    true if the add-on is selectec


123
124
125
# File 'src/lib/registration/addon.rb', line 123

def selected?
  Addon.selected.include?(self)
end

#to_h(release_type_string: false) ⇒ Hash

Convert to a Hash, exports only the basic Addon properties

Parameters:

  • release_type_string (Boolean)

    if true the "release_type" atribute will be always a String (nil will be converted to "nil")

Returns:

  • (Hash)

    Hash with basic Addon properties


191
192
193
194
195
196
197
198
# File 'src/lib/registration/addon.rb', line 191

def to_h(release_type_string: false)
  {
    "name"         => identifier,
    "arch"         => arch,
    "version"      => version,
    "release_type" => (release_type.nil? && release_type_string) ? "nil" : release_type
  }
end

#toggle_selectedObject

toggle the selection state of the add-on


138
139
140
141
142
143
144
# File 'src/lib/registration/addon.rb', line 138

def toggle_selected
  if selected?
    unselected
  else
    selected
  end
end

#unregisteredObject

just internally mark the addon as NOT registered, not a real unregistration


158
159
160
# File 'src/lib/registration/addon.rb', line 158

def unregistered
  Addon.registered.delete(self) if registered?
end

#unselectedObject

unselect the add-on


133
134
135
# File 'src/lib/registration/addon.rb', line 133

def unselected
  Addon.selected.delete(self) if selected?
end

#updates_addon?(old_addon) ⇒ Boolean

Checks whether this addon updates an old addon

Parameters:

  • old_addon (Hash)

    addon Hash received from pkg-bindings

Returns:

  • (Boolean)

    true if it updates the old addon, false otherwise


212
213
214
# File 'src/lib/registration/addon.rb', line 212

def updates_addon?(old_addon)
  old_addon["name"] == identifier || old_addon["name"] == @pure_addon.former_identifier
end