Class: PuppetX::PuppetLabs::ScheduledTask::Trigger::V2::Month Private

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet_x/puppetlabs/scheduled_task/trigger.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Gets or sets the months of the year during which the task runs.

Constant Summary collapse

TASK_JANUARY =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The task will run in January.

0x1
TASK_FEBRUARY =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The task will run in February.

0x2
TASK_MARCH =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The task will run in March.

0x4
TASK_APRIL =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The task will run in April.

0x8
TASK_MAY =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The task will run in May.

0x10
TASK_JUNE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The task will run in June.

0x20
TASK_JULY =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The task will run in July.

0x40
TASK_AUGUST =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The task will run in August.

0x80
TASK_SEPTEMBER =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The task will run in September.

0x100
TASK_OCTOBER =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The task will run in October.

0x200
TASK_NOVEMBER =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The task will run in November.

0x400
TASK_DECEMBER =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The task will run in December.

0x800
MAX_VALUE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

12 bits for 12 possible months to set

0b111111111111
MONTHNUM_CONST_MAP =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Month number to HEX map

{
  1  => TASK_JANUARY,
  2  => TASK_FEBRUARY,
  3  => TASK_MARCH,
  4  => TASK_APRIL,
  5  => TASK_MAY,
  6  => TASK_JUNE,
  7  => TASK_JULY,
  8  => TASK_AUGUST,
  9  => TASK_SEPTEMBER,
  10 => TASK_OCTOBER,
  11 => TASK_NOVEMBER,
  12 => TASK_DECEMBER,
}.freeze

Class Method Summary collapse

Class Method Details

.bitmask_to_indexes(bitmask) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Converts bitmask to indexes



540
541
542
543
544
545
546
547
548
549
# File 'lib/puppet_x/puppetlabs/scheduled_task/trigger.rb', line 540

def self.bitmask_to_indexes(bitmask)
  bitmask = Integer(bitmask)
  if bitmask.negative? || bitmask > MAX_VALUE
    raise ArgumentError, "bitmask must be specified as an integer from 0 to #{MAX_VALUE.to_s(10)}"
  end

  MONTHNUM_CONST_MAP.values.each_with_object([]) do |day, indexes|
    indexes << MONTHNUM_CONST_MAP.key(day) if bitmask & day != 0
  end
end

.indexesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns month indexes



522
523
524
# File 'lib/puppet_x/puppetlabs/scheduled_task/trigger.rb', line 522

def self.indexes
  @indexes ||= MONTHNUM_CONST_MAP.keys.freeze
end

.indexes_to_bitmask(month_indexes) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Converts indexes to bitmask

Raises:

  • (ArgumentError)


527
528
529
530
531
532
533
534
535
536
537
# File 'lib/puppet_x/puppetlabs/scheduled_task/trigger.rb', line 527

def self.indexes_to_bitmask(month_indexes)
  month_indexes = [month_indexes].flatten.map do |m|
    Integer(m)
  rescue
    m
  end
  invalid_months = month_indexes - MONTHNUM_CONST_MAP.keys
  raise ArgumentError, 'Month must be specified as an integer in the range 1-12' unless invalid_months.empty?

  month_indexes.reduce(0) { |bitmask, month_index| bitmask | MONTHNUM_CONST_MAP[month_index] }
end