Class: ChefAB::BaseUpgrader

Inherits:
Object
  • Object
show all
Defined in:
lib/chef-ab/base_upgrader.rb

Direct Known Subclasses

TimeIPBasedUpgrader, TimeLinearUpgrader

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ BaseUpgrader

Returns a new instance of BaseUpgrader.



7
8
9
10
11
12
13
14
15
# File 'lib/chef-ab/base_upgrader.rb', line 7

def initialize(options)
  @node_id = options[:node_id]
  raise "node_id is a mandatory options" unless @node_id
  if @node_id.is_a? Integer
    @hash = node_id
  else
    @hash = Zlib.crc32 (@node_id.to_s)
  end
end

Instance Attribute Details

#hashObject

Returns the value of attribute hash.



5
6
7
# File 'lib/chef-ab/base_upgrader.rb', line 5

def hash
  @hash
end

#node_idObject

Returns the value of attribute node_id.



5
6
7
# File 'lib/chef-ab/base_upgrader.rb', line 5

def node_id
  @node_id
end

Instance Method Details

#execute(&block) ⇒ Object



21
22
23
24
25
# File 'lib/chef-ab/base_upgrader.rb', line 21

def execute(&block)
  if block_given? && should_execute?
    block.call
  end
end

#should_execute?(threshold) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/chef-ab/base_upgrader.rb', line 17

def should_execute?(threshold)
  @hash < threshold
end