Sha256: 246ba5ae637f7029d5f4c2e539b660d5d38e7f12bbc8e7c0226d9bfd26db57f1

Contents?: true

Size: 814 Bytes

Versions: 72

Compression:

Stored size: 814 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

        protected

        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

72 entries across 72 versions & 1 rubygems

Version Path
coveragebook_components-0.19.9 app/components/coco/concerns/has_name.rb
coveragebook_components-0.19.8 app/components/coco/concerns/has_name.rb
coveragebook_components-0.19.7 app/components/coco/concerns/has_name.rb
coveragebook_components-0.19.6 app/components/coco/concerns/has_name.rb
coveragebook_components-0.19.5 app/components/coco/concerns/has_name.rb
coveragebook_components-0.19.4 app/components/coco/concerns/has_name.rb
coveragebook_components-0.19.3 app/components/coco/concerns/has_name.rb
coveragebook_components-0.19.2 app/components/coco/concerns/has_name.rb
coveragebook_components-0.19.1 app/components/coco/concerns/has_name.rb
coveragebook_components-0.19.0 app/components/coco/concerns/has_name.rb
coveragebook_components-0.18.8 app/components/coco/concerns/has_name.rb
coveragebook_components-0.18.7 app/components/coco/concerns/has_name.rb
coveragebook_components-0.18.0 app/components/coco/concerns/has_name.rb
coveragebook_components-0.17.7 app/components/coco/concerns/has_name.rb
coveragebook_components-0.17.6 app/components/coco/concerns/has_name.rb
coveragebook_components-0.17.5 app/components/coco/concerns/has_name.rb
coveragebook_components-0.17.4 app/components/coco/concerns/has_name.rb
coveragebook_components-0.17.3 app/components/coco/concerns/has_name.rb
coveragebook_components-0.17.2 app/components/coco/concerns/has_name.rb
coveragebook_components-0.17.1 app/components/coco/concerns/has_name.rb