Class: PuppetX::PuppetLabs::ScheduledTask::Trigger::V2::Day 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 days of the week in which the task runs.

Constant Summary collapse

TASK_SUNDAY =

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 on Sunday.

0x1
TASK_MONDAY =

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 on Monday.

0x2
TASK_TUESDAY =

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 on Tuesday.

0x4
TASK_WEDNESDAY =

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 on Wednesday.

0x8
TASK_THURSDAY =

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 on Thursday.

0x10
TASK_FRIDAY =

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 on Friday.

0x20
TASK_SATURDAY =

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 on Saturday.

0x40
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.

7 bits for 7 possible days to set

0b1111111
DAY_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.

Day name to HEX map

{
  'sun'   => TASK_SUNDAY,
  'mon'   => TASK_MONDAY,
  'tues'  => TASK_TUESDAY,
  'wed'   => TASK_WEDNESDAY,
  'thurs' => TASK_THURSDAY,
  'fri'   => TASK_FRIDAY,
  'sat'   => TASK_SATURDAY,
}.freeze

Class Method Summary collapse

Class Method Details

.bitmask_to_names(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 day names



385
386
387
388
389
390
391
392
393
394
# File 'lib/puppet_x/puppetlabs/scheduled_task/trigger.rb', line 385

def self.bitmask_to_names(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

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

.namesObject

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 day names



366
367
368
# File 'lib/puppet_x/puppetlabs/scheduled_task/trigger.rb', line 366

def self.names
  @names ||= DAY_CONST_MAP.keys.freeze
end

.names_to_bitmask(day_names) ⇒ 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 day names to bitmask

Raises:

  • (ArgumentError)


376
377
378
379
380
381
382
# File 'lib/puppet_x/puppetlabs/scheduled_task/trigger.rb', line 376

def self.names_to_bitmask(day_names)
  day_names = [day_names].flatten
  invalid_days = day_names - DAY_CONST_MAP.keys
  raise ArgumentError, "Days_of_week value #{invalid_days.join(', ')} is invalid. Expected sun, mon, tue, wed, thu, fri or sat." unless invalid_days.empty?

  day_names.reduce(0) { |bitmask, day| bitmask | DAY_CONST_MAP[day] }
end

.valuesObject

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 day task values



371
372
373
# File 'lib/puppet_x/puppetlabs/scheduled_task/trigger.rb', line 371

def self.values
  @values ||= DAY_CONST_MAP.values.freeze
end