Sha256: 73a5919369dfb6eacca4c0f3e1ac58e9b45cd96324c14aa55e7206193bef2de8

Contents?: true

Size: 1.36 KB

Versions: 11

Compression:

Stored size: 1.36 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,
          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)
          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
        rescue NameError
          nil
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
avm-tools-0.64.2 lib/avm/projects/stereotype.rb
avm-tools-0.64.1 lib/avm/projects/stereotype.rb
avm-tools-0.64.0 lib/avm/projects/stereotype.rb
avm-tools-0.63.0 lib/avm/projects/stereotype.rb
avm-tools-0.62.4 lib/avm/projects/stereotype.rb
avm-tools-0.62.3 lib/avm/projects/stereotype.rb
avm-tools-0.62.2 lib/avm/projects/stereotype.rb
avm-tools-0.62.1 lib/avm/projects/stereotype.rb
avm-tools-0.62.0 lib/avm/projects/stereotype.rb
avm-tools-0.61.0 lib/avm/projects/stereotype.rb
avm-tools-0.60.0 lib/avm/projects/stereotype.rb