lib/ariadne/yard/component_ref.rb



# frozen_string_literal: true

# :nocov:
module Ariadne
  module Yard
    # :nodoc:
    class ComponentRef
      ATTR_DEFAULTS = {
        js: false,
        examples: true,
        form_component: false,
      }.freeze

      attr_reader :klass, :attrs

      def initialize(klass, attrs)
        @klass = klass
        @attrs = attrs
      end

      def requires_js?
        @attrs.fetch(:js, ATTR_DEFAULTS[:js])
      end

      def should_have_examples?
        @attrs.fetch(:examples, ATTR_DEFAULTS[:examples])
      end

      def form_component?
        @attrs.fetch(:form_component, ATTR_DEFAULTS[:form_component])
      end

      def source_url
        @source_url ||= begin
          path = klass.name.split("::").map(&:underscore).join("/")
          "https://github.com/yettoapp/ariadne/tree/main/app/components/#{path}.rb"
        end
      end

      def lookbook_url
        @lookbook_url ||= begin
          path = klass.name.underscore.gsub("_component", "")
          "https://ariadne.style/view-components/lookbook/inspect/#{path}/default/"
        end
      end
    end
  end
end
# :nocov: