Class: Sqreen::Weave::Budget

Inherits:
Object
  • Object
show all
Includes:
Log::Loggable
Defined in:
lib/sqreen/weave/budget.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Log::Loggable

included, #logger

Constructor Details

#initialize(threshold, ratio = nil) ⇒ Budget

Returns a new instance of Budget.



12
13
14
15
# File 'lib/sqreen/weave/budget.rb', line 12

def initialize(threshold, ratio = nil)
  @threshold = threshold
  @ratio = ratio
end

Class Attribute Details

.currentObject (readonly)

Returns the value of attribute current.



33
34
35
# File 'lib/sqreen/weave/budget.rb', line 33

def current
  @current
end

Instance Attribute Details

#ratioObject (readonly)

Returns the value of attribute ratio.



26
27
28
# File 'lib/sqreen/weave/budget.rb', line 26

def ratio
  @ratio
end

#thresholdObject (readonly)

Returns the value of attribute threshold.



25
26
27
# File 'lib/sqreen/weave/budget.rb', line 25

def threshold
  @threshold
end

Class Method Details

.update(opts = nil) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/sqreen/weave/budget.rb', line 35

def update(opts = nil)
  Sqreen::Weave.logger.info("budget update:#{opts.inspect}")

  return @current = nil if opts.nil? || opts.empty?

  threshold = opts[:threshold]
  ratio = opts[:ratio]

  @current = new(threshold, ratio)
end

Instance Method Details

#dynamic?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/sqreen/weave/budget.rb', line 21

def dynamic?
  threshold && ratio
end

#static?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/sqreen/weave/budget.rb', line 17

def static?
  threshold && !ratio
end

#to_hObject



28
29
30
# File 'lib/sqreen/weave/budget.rb', line 28

def to_h
  { threshold: threshold, ratio: ratio }
end