Sha256: 6569ab530b862e3f3514648b1fb42847bc188d72a9e28d0769fad95c83a699e3

Contents?: true

Size: 1.5 KB

Versions: 19

Compression:

Stored size: 1.5 KB

Contents

require 'zendesk_apps_tools/array_patch'

module ZendeskAppsTools
  module ManifestHandler
    VERSION_PARTS = %i(major minor patch)

    attr_reader :semver

    VERSION_PARTS.each do |m|
      define_method m do
        load_manifest
        read_version
        normalize_version
        super()
        update_version
        write_manifest
        post_actions
      end
    end

    private

    def manifest_json_path
      'manifest.json'
    end

    def load_manifest
      manifest_json = File.read(manifest_json_path)
      @manifest = JSON.load(manifest_json)
    rescue => e
      say(e.message, :red) and exit 1
    end

    def read_version
      version = @manifest.fetch('version', '0.0.0')
      sem_parts = sub_semver(version)
      @semver = sem_parts.names.map(&:to_sym).zip(sem_parts.to_a.drop(1)).to_h
    end

    def normalize_version
      VERSION_PARTS.each do |part|
        semver[part] = (semver[part] || '0').to_i
      end
    end

    def update_version
      @manifest['version'] = version
    end

    def write_manifest
      File.open(manifest_json_path, 'w') do |f|
        f.write(JSON.pretty_generate(@manifest))
        f.write("\n")
      end
    end

    def sub_semver(v)
      v.match(/\A(?<v>v)?(?<major>\d+)(?:\.(?<minor>\d+)(?:\.(?<patch>\d+))?)?\Z/)
    end

    def version(v: false)
      [
        v ? 'v' : semver[:v],
        [
          semver[:major],
          semver[:minor],
          semver[:patch]
        ].compact.map(&:to_s).join('.')
      ].compact.join
    end
  end
end

Version data entries

19 entries across 19 versions & 2 rubygems

Version Path
zendesk_apps_tools-1.34.0 lib/zendesk_apps_tools/manifest_handler.rb
zendesk_apps_tools-1.34.1 lib/zendesk_apps_tools/manifest_handler.rb
zendesk_apps_tools-1.33.3 lib/zendesk_apps_tools/manifest_handler.rb
zendesk_apps_tools-1.33.2 lib/zendesk_apps_tools/manifest_handler.rb
xat-1.32.0 lib/zendesk_apps_tools/manifest_handler.rb
zendesk_apps_tools-1.32.0 lib/zendesk_apps_tools/manifest_handler.rb
zendesk_apps_tools-1.31.1 lib/zendesk_apps_tools/manifest_handler.rb
zendesk_apps_tools-1.31.0 lib/zendesk_apps_tools/manifest_handler.rb
zendesk_apps_tools-1.30.0 lib/zendesk_apps_tools/manifest_handler.rb
zendesk_apps_tools-1.29.0 lib/zendesk_apps_tools/manifest_handler.rb
zendesk_apps_tools-1.28.3 lib/zendesk_apps_tools/manifest_handler.rb
zendesk_apps_tools-1.28.2 lib/zendesk_apps_tools/manifest_handler.rb
zendesk_apps_tools-1.28.0 lib/zendesk_apps_tools/manifest_handler.rb
zendesk_apps_tools-1.27.0 lib/zendesk_apps_tools/manifest_handler.rb
zendesk_apps_tools-1.25.0 lib/zendesk_apps_tools/manifest_handler.rb
zendesk_apps_tools-1.24.3 lib/zendesk_apps_tools/manifest_handler.rb
zendesk_apps_tools-1.24.2 lib/zendesk_apps_tools/manifest_handler.rb
zendesk_apps_tools-1.24.1 lib/zendesk_apps_tools/manifest_handler.rb
zendesk_apps_tools-1.24.0 lib/zendesk_apps_tools/manifest_handler.rb