Class: Katello::ContentOverride

Inherits:
Object
  • Object
show all
Defined in:
app/models/katello/content_override.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content_label, params = {}) ⇒ ContentOverride



5
6
7
8
9
10
11
12
13
# File 'app/models/katello/content_override.rb', line 5

def initialize(, params = {})
  @content_label = 
  if params.key?(:enabled)
    self.enabled = params[:enabled]
  else
    @name = params[:name]
    @value = params[:value]
  end
end

Instance Attribute Details

#content_labelObject

Returns the value of attribute content_label.



3
4
5
# File 'app/models/katello/content_override.rb', line 3

def 
  @content_label
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'app/models/katello/content_override.rb', line 3

def name
  @name
end

#valueObject

Returns the value of attribute value.



3
4
5
# File 'app/models/katello/content_override.rb', line 3

def value
  @value
end

Class Method Details

.fetch(params) ⇒ Object



59
60
61
62
63
64
65
# File 'app/models/katello/content_override.rb', line 59

def self.fetch(params)
  if params.is_a?(ContentOverride)
    params
  else
    ContentOverride.new(params["content_label"], :name => params["name"], :value => params["value"])
  end
end

.from_entitlement_hash(entitlement_hash) ⇒ Object



37
38
39
40
41
42
43
# File 'app/models/katello/content_override.rb', line 37

def self.from_entitlement_hash(entitlement_hash)
  ent_hash =  entitlement_hash.with_indifferent_access
  override = ContentOverride.new(ent_hash["contentLabel"])
  override.name = ent_hash["name"]
  override.value = ent_hash["value"]
  override
end

Instance Method Details

#==(other) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'app/models/katello/content_override.rb', line 45

def ==(other)
  if self.class == other.class
    self. == other. &&
      self.name == other.name &&
      self.value == other.value
  else
    super
  end
end

#computed_valueObject



20
21
22
23
24
25
26
27
28
# File 'app/models/katello/content_override.rb', line 20

def computed_value
  return if self.value.nil?

  if self.name == "enabled"
    ::Foreman::Cast.to_bool(self.value)
  else
    self.value
  end
end

#enabled=(value = nil) ⇒ Object



15
16
17
18
# File 'app/models/katello/content_override.rb', line 15

def enabled=(value = nil)
  @name = "enabled"
  @value = value
end

#to_entitlement_hashObject



30
31
32
33
34
35
# File 'app/models/katello/content_override.rb', line 30

def to_entitlement_hash
  ret = {"contentLabel" => @content_label}
  ret["name"] = @name if @name
  ret["value"] = @value if @value
  ret.with_indifferent_access
end

#to_hashObject



55
56
57
# File 'app/models/katello/content_override.rb', line 55

def to_hash
  {"content_label" => @content_label, "name" => @name, "value" => @value}
end