Sha256: 106ac3d59c8ba48e43ed78c2d978a18b8060317c49734a6bfba2fcd5aa9c0461

Contents?: true

Size: 1.41 KB

Versions: 156

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true

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

module Avm
  module Projects
    module Stereotype
      class << self
        attr_reader :stereotypes

        def included(base)
          @stereotypes ||= []
          @stereotypes << 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
      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

156 entries across 156 versions & 2 rubygems

Version Path
avm-tools-0.140.0 lib/avm/projects/stereotype.rb
eac_tools-0.36.0 sub/avm-tools/lib/avm/projects/stereotype.rb
avm-tools-0.139.0 lib/avm/projects/stereotype.rb
eac_tools-0.35.0 sub/avm-tools/lib/avm/projects/stereotype.rb
avm-tools-0.138.0 lib/avm/projects/stereotype.rb
eac_tools-0.34.0 sub/avm-tools/lib/avm/projects/stereotype.rb
avm-tools-0.137.0 lib/avm/projects/stereotype.rb
eac_tools-0.33.0 sub/avm-tools/lib/avm/projects/stereotype.rb
eac_tools-0.32.0 sub/avm-tools/lib/avm/projects/stereotype.rb
avm-tools-0.136.2 lib/avm/projects/stereotype.rb
eac_tools-0.31.1 sub/avm-tools/lib/avm/projects/stereotype.rb
eac_tools-0.31.0 sub/avm-tools/lib/avm/projects/stereotype.rb
avm-tools-0.136.1 lib/avm/projects/stereotype.rb
eac_tools-0.30.0 sub/avm-tools/lib/avm/projects/stereotype.rb
eac_tools-0.29.0 sub/avm-tools/lib/avm/projects/stereotype.rb
avm-tools-0.136.0 lib/avm/projects/stereotype.rb
eac_tools-0.28.0 sub/avm-tools/lib/avm/projects/stereotype.rb
eac_tools-0.27.2 sub/avm-tools/lib/avm/projects/stereotype.rb
eac_tools-0.27.1 sub/avm-tools/lib/avm/projects/stereotype.rb
avm-tools-0.135.0 lib/avm/projects/stereotype.rb