Sha256: 6c77d4efe5bd41ebd3f887b7759a8ef4f80abec7f39859e26fd754a729a8b859

Contents?: true

Size: 996 Bytes

Versions: 2

Compression:

Stored size: 996 Bytes

Contents

# frozen_string_literal: true

require "active_support/concern"

module Yattho
  # :nodoc:
  module Status
    # DSL to allow components to register their status.
    #
    # Example:
    #
    # class MyComponent < ViewComponent::Base
    #   include Yattho::Status::Dsl
    #   status :beta
    # end
    module Dsl
      extend ActiveSupport::Concern

      STATUSES = {
        alpha: :alpha,
        beta: :beta,
        stable: :stable,
        deprecated: :deprecated,
        experimental: :experimental
      }.freeze

      class UnknownStatusError < StandardError; end

      included do
        class_attribute :component_status, instance_writer: false, default: STATUSES[:alpha]
      end

      class_methods do
        def status(status = nil)
          return component_status if status.nil?

          raise UnknownStatusError, "status #{status} does not exist" if STATUSES[status].nil?

          self.component_status = STATUSES[status]
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
yattho_view_components-0.1.1 app/lib/yattho/status/dsl.rb
yattho_view_components-0.0.1 app/lib/yattho/status/dsl.rb