Sha256: 41baff6ad9e0bbe71eca819d70e8414919e875c38ae0f56099cbe86723a5fa2f

Contents?: true

Size: 1.41 KB

Versions: 149

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true

require 'active_support/core_ext/string/inflections'
require 'colorized_string'

module Avm
  module Launcher
    module Stereotype
      class << self
        def included(base)
          base.extend(ClassMethods)
        end

        def git_stereotypes
          stereotypes.select { |c| c.name.demodulize.downcase.match('git') }
        end

        def nogit_stereotypes
          stereotypes - git_stereotypes
        end

        def stereotypes
          ::Avm::Registry.launcher_stereotypes.available
        end
      end

      module ClassMethods
        def label
          ::ColorizedString.new(stereotype_name).send(color)
        end

        def stereotype_name
          name.demodulize
        end

        {
          local_project_mixin: ::Module,
          publish: ::Class,
          update: ::Class,
          version_bump: ::Class,
          warp: ::Class
        }.each do |name, is_a|
          define_method "#{name}_#{is_a.name.underscore}" do
            sub_constant(name.to_s.camelcase, is_a)
          end
        end

        private

        def sub_constant(constant_name, is_a)
          return nil unless const_defined?(constant_name)

          constant = const_get(constant_name)
          unless is_a.if_present(true) { |v| constant.is_a?(v) }
            raise("#{constant} is not a #{is_a}")
          end

          constant
        end
      end
    end
  end
end

Version data entries

149 entries across 149 versions & 2 rubygems

Version Path
avm-0.94.1 lib/avm/launcher/stereotype.rb
eac_tools-0.98.0 sub/avm/lib/avm/launcher/stereotype.rb
avm-0.94.0 lib/avm/launcher/stereotype.rb
eac_tools-0.94.0 sub/avm/lib/avm/launcher/stereotype.rb
avm-0.93.0 lib/avm/launcher/stereotype.rb
eac_tools-0.92.0 sub/avm/lib/avm/launcher/stereotype.rb
avm-0.92.0 lib/avm/launcher/stereotype.rb
eac_tools-0.91.0 sub/avm/lib/avm/launcher/stereotype.rb
avm-0.90.1 lib/avm/launcher/stereotype.rb
eac_tools-0.87.1 sub/avm/lib/avm/launcher/stereotype.rb
avm-0.90.0 lib/avm/launcher/stereotype.rb
eac_tools-0.87.0 sub/avm/lib/avm/launcher/stereotype.rb
avm-0.89.0 lib/avm/launcher/stereotype.rb
eac_tools-0.86.12 sub/avm/lib/avm/launcher/stereotype.rb
avm-0.88.0 lib/avm/launcher/stereotype.rb
eac_tools-0.86.11 sub/avm/lib/avm/launcher/stereotype.rb
avm-0.87.0 lib/avm/launcher/stereotype.rb
eac_tools-0.86.8 sub/avm/lib/avm/launcher/stereotype.rb
avm-0.86.2 lib/avm/launcher/stereotype.rb
eac_tools-0.86.7 sub/avm/lib/avm/launcher/stereotype.rb