Class: Vara::StaticVersioner

Inherits:
Object
  • Object
show all
Defined in:
lib/vara/static_versioner.rb

Constant Summary collapse

PRODUCT_VERSION_KEY =
'product_version'.freeze
TO_VERSION_KEY =
'to_version'.freeze
MIGRATIONS_KEY =
'migrations'.freeze
MIGRATIONS_RULES_KEY =
'rules'.freeze
MIGRATIONS_RULES_TO_KEY =
'to'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(product_directory_path, version) ⇒ StaticVersioner

Returns a new instance of StaticVersioner.

Parameters:

  • product_directory_path (String)
  • version (String)

    the product version



13
14
15
16
17
18
19
20
21
22
# File 'lib/vara/static_versioner.rb', line 13

def initialize(product_directory_path, version)
  begin
    Gem::Version.create(version)
  rescue
    raise Vara::VersionError, "Invalid version: #{version}"
  end

  @product_directory_path = product_directory_path
  @version = version
end

Instance Method Details

#update_content_migrations(migrations_hash) ⇒ Hash

Returns content migrations with product version value updated if necessary.

Parameters:

  • migrations_hash (Hash)

    Hash contents of full content migrations

Returns:

  • (Hash)

    content migrations with product version value updated if necessary



33
34
35
36
37
38
39
40
41
42
# File 'lib/vara/static_versioner.rb', line 33

def update_content_migrations(migrations_hash)
  migrations_hash[TO_VERSION_KEY] = version unless migrations_hash[TO_VERSION_KEY].nil?
  migrations_hash.fetch(MIGRATIONS_KEY, []).each do |migration|
    migration.fetch(MIGRATIONS_RULES_KEY, []).each do |rule|
      next unless updates_product_version?(rule)
      rule[MIGRATIONS_RULES_TO_KEY] = version
    end
  end
  migrations_hash
end

#update_metadata(metadata_hash) ⇒ Hash

Returns product metadata with product version value updated.

Parameters:

  • metadata_hash (Hash)

    Hash contents of full product metadata

Returns:

  • (Hash)

    product metadata with product version value updated



26
27
28
29
# File 'lib/vara/static_versioner.rb', line 26

def ()
  [PRODUCT_VERSION_KEY].gsub!(/^.*$/, version)
  
end