Sha256: d9c850c48f673030e25e796d2051dded9f95f812e428d8cbb1681806816ddf78

Contents?: true

Size: 812 Bytes

Versions: 2

Compression:

Stored size: 812 Bytes

Contents

module Coco
  module Concerns
    module HasName
      extend ActiveSupport::Concern

      def component_name
        @_component_name ||= self.class.send(:component_name)
      end

      class_methods do
        def component_name(name = nil)
          if name
            @_component_name = name.to_s.tr("_", "-")
          else
            @_component_name ||= [
              component_group,
              component_path.demodulize.underscore.tr("_", "-")
            ].compact.uniq.join("-")
          end
        end

        private

        def component_group
          @_component_group ||= component_path.split("::").first.underscore.tr("_", "-")
        end

        def component_path
          name.to_s.delete_suffix("Component").delete_prefix("Coco::")
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
coveragebook_components-0.5.1 app/components/coco/concerns/has_name.rb
coveragebook_components-0.5.0 app/components/coco/concerns/has_name.rb