Class: PgCron::Generators::VersionHelper Private

Inherits:
Object
  • Object
show all
Defined in:
lib/generators/pg_cron/version_helper.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.

Works out which version of a definition we are creating.

Copied from Fx::Generators::VersionHelper. The scan is over db/cron rather than db/functions, and there is one type instead of two, so definition_for_version takes no type.

Instance Method Summary collapse

Constructor Details

#initialize(file_name:, definition_path:) ⇒ VersionHelper

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 a new instance of VersionHelper.



13
14
15
16
# File 'lib/generators/pg_cron/version_helper.rb', line 13

def initialize(file_name:, definition_path:)
  @file_name = file_name
  @definition_path = definition_path
end

Instance Method Details

#creating_new? ⇒ Boolean

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:

  • (Boolean)


30
31
32
# File 'lib/generators/pg_cron/version_helper.rb', line 30

def creating_new?
  previous_version == 0
end

#current_version ⇒ 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.



22
23
24
# File 'lib/generators/pg_cron/version_helper.rb', line 22

def current_version
  previous_version.next
end

#definition_for_version(version:) ⇒ 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.



34
35
36
# File 'lib/generators/pg_cron/version_helper.rb', line 34

def definition_for_version(version:)
  PgCron::Definition.job(name: file_name, version: version)
end

#previous_version ⇒ 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.



18
19
20
# File 'lib/generators/pg_cron/version_helper.rb', line 18

def previous_version
  @previous_version ||= existing_versions.max || 0
end

#updating_existing? ⇒ Boolean

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:

  • (Boolean)


26
27
28
# File 'lib/generators/pg_cron/version_helper.rb', line 26

def updating_existing?
  previous_version > 0
end