Class: Lilac::CLI::ComponentName

Inherits:
Object
  • Object
show all
Defined in:
lib/lilac/cli/build/component_name.rb

Overview

Value object for a .lil component's kebab-case name. Holds the raw string and exposes the derived forms the build pipeline needs:

name = ComponentName.new("admin--user-card")
name.ruby_class                 # => "Admin::UserCard"
name.to_s                       # => "admin--user-card"

-- separates namespace segments, - separates words within a segment. Empty segments (leading/trailing --, double - between words) raise at construction so misnamed files fail loudly rather than emitting ::Foo / Foo:: downstream.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kebab) ⇒ ComponentName

Returns a new instance of ComponentName.



20
21
22
23
# File 'lib/lilac/cli/build/component_name.rb', line 20

def initialize(kebab)
  @kebab = kebab.to_s
  @ruby_class = build_ruby_class
end

Instance Attribute Details

#kebabObject (readonly)

Returns the value of attribute kebab.



18
19
20
# File 'lib/lilac/cli/build/component_name.rb', line 18

def kebab
  @kebab
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



33
34
35
# File 'lib/lilac/cli/build/component_name.rb', line 33

def ==(other)
  other.is_a?(ComponentName) && other.kebab == @kebab
end

#hashObject



38
39
40
# File 'lib/lilac/cli/build/component_name.rb', line 38

def hash
  @kebab.hash
end

#ruby_classObject



25
26
27
# File 'lib/lilac/cli/build/component_name.rb', line 25

def ruby_class
  @ruby_class
end

#to_sObject



29
30
31
# File 'lib/lilac/cli/build/component_name.rb', line 29

def to_s
  @kebab
end