Sha256: 246ba5ae637f7029d5f4c2e539b660d5d38e7f12bbc8e7c0226d9bfd26db57f1

Contents?: true

Size: 814 Bytes

Versions: 71

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

71 entries across 71 versions & 1 rubygems

Version Path
coveragebook_components-0.16.0 app/components/coco/concerns/has_name.rb
coveragebook_components-0.15.0 app/components/coco/concerns/has_name.rb
coveragebook_components-0.14.0 app/components/coco/concerns/has_name.rb
coveragebook_components-0.13.1 app/components/coco/concerns/has_name.rb
coveragebook_components-0.13.0 app/components/coco/concerns/has_name.rb
coveragebook_components-0.12.2 app/components/coco/concerns/has_name.rb
coveragebook_components-0.12.1 app/components/coco/concerns/has_name.rb
coveragebook_components-0.12.0 app/components/coco/concerns/has_name.rb
coveragebook_components-0.11.0 app/components/coco/concerns/has_name.rb
coveragebook_components-0.10.1.beta.2 app/components/coco/concerns/has_name.rb
coveragebook_components-0.10.1.beta.1 app/components/coco/concerns/has_name.rb
coveragebook_components-0.10.1.beta.0 app/components/coco/concerns/has_name.rb
coveragebook_components-0.10.0 app/components/coco/concerns/has_name.rb
coveragebook_components-0.9.1 app/components/coco/concerns/has_name.rb
coveragebook_components-0.9.0 app/components/coco/concerns/has_name.rb
coveragebook_components-0.8.9 app/components/coco/concerns/has_name.rb
coveragebook_components-0.8.8 app/components/coco/concerns/has_name.rb
coveragebook_components-0.8.7 app/components/coco/concerns/has_name.rb
coveragebook_components-0.8.6 app/components/coco/concerns/has_name.rb
coveragebook_components-0.8.5 app/components/coco/concerns/has_name.rb