Class: Metatron::Templates::LimitRange::Limit

Inherits:
Object
  • Object
show all
Defined in:
lib/metatron/templates/limit_range.rb

Overview

Limit is an internal class used to represent the limits in a LimitRange resource, and to provide a consistent interface for rendering them. It is not intended to be used outside of this class. Eventually, it may be used to provide validation for the limits.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, default: nil, default_request: nil, max: nil, max_limit_request_ratio: nil, min: nil) ⇒ Limit

Returns a new instance of Limit.



23
24
25
26
27
28
29
30
31
# File 'lib/metatron/templates/limit_range.rb', line 23

def initialize(type:, default: nil, default_request: nil, max: nil,
               max_limit_request_ratio: nil, min: nil)
  @type = type
  @default = default
  @default_request = default_request
  @max = max
  @max_limit_request_ratio = max_limit_request_ratio
  @min = min
end

Instance Attribute Details

#defaultObject

Returns the value of attribute default.



12
13
14
# File 'lib/metatron/templates/limit_range.rb', line 12

def default
  @default
end

#default_requestObject Also known as: defaultRequest

Returns the value of attribute default_request.



12
13
14
# File 'lib/metatron/templates/limit_range.rb', line 12

def default_request
  @default_request
end

#maxObject

Returns the value of attribute max.



12
13
14
# File 'lib/metatron/templates/limit_range.rb', line 12

def max
  @max
end

#max_limit_request_ratioObject Also known as: maxLimitRequestRatio

Returns the value of attribute max_limit_request_ratio.



12
13
14
# File 'lib/metatron/templates/limit_range.rb', line 12

def max_limit_request_ratio
  @max_limit_request_ratio
end

#minObject

Returns the value of attribute min.



12
13
14
# File 'lib/metatron/templates/limit_range.rb', line 12

def min
  @min
end

#typeObject

Returns the value of attribute type.



12
13
14
# File 'lib/metatron/templates/limit_range.rb', line 12

def type
  @type
end

Class Method Details

.to_limit(limit) ⇒ Object



18
19
20
# File 'lib/metatron/templates/limit_range.rb', line 18

def to_limit(limit)
  limit.is_a?(Limit) ? limit : new(**limit)
end

Instance Method Details

#renderObject



33
34
35
36
37
38
39
40
41
42
# File 'lib/metatron/templates/limit_range.rb', line 33

def render
  {
    type:,
    default:,
    defaultRequest:,
    max:,
    maxLimitRequestRatio:,
    min:
  }.compact
end