Class: Docks::NamingConventions::SUIT

Inherits:
Base
  • Object
show all
Defined in:
lib/docks/naming_conventions/suit_naming_convention.rb

Constant Summary collapse

STATEFUL_WORDS =
%w(is)

Instance Method Summary collapse

Instance Method Details

#base_component(component_name) ⇒ Object



8
9
10
# File 'lib/docks/naming_conventions/suit_naming_convention.rb', line 8

def base_component(component_name)
  component_name.split("-").first
end

#base_component?(component_name) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/docks/naming_conventions/suit_naming_convention.rb', line 12

def base_component?(component_name)
  component_name == base_component(component_name)
end

#clean_variation_name(variation_name, component_name) ⇒ Object



25
26
27
28
29
# File 'lib/docks/naming_conventions/suit_naming_convention.rb', line 25

def clean_variation_name(variation_name, component_name)
  return variation_name if disconnected_state?(variation_name)
  variation_name = variation_name.sub(Regexp.new("^(?:#{component_name})?(?:--)?"), "")
  "#{component_name}--#{variation_name}"
end

#component(component_name) ⇒ Object



16
17
18
# File 'lib/docks/naming_conventions/suit_naming_convention.rb', line 16

def component(component_name)
  component_name.gsub(/--[^\-]*/, "")
end

#disconnected_state?(state_name) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/docks/naming_conventions/suit_naming_convention.rb', line 40

def disconnected_state?(state_name)
  state?(state_name) && !state_name.include?("--")
end

#parent_component(component_name) ⇒ Object



20
21
22
23
# File 'lib/docks/naming_conventions/suit_naming_convention.rb', line 20

def parent_component(component_name)
  component_name = component(component_name)
  component_name.sub(/-[^\-]*$/, "")
end

#state?(state_name) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
# File 'lib/docks/naming_conventions/suit_naming_convention.rb', line 31

def state?(state_name)
  state_name = state_name.split("--").last
  STATEFUL_WORDS.any? { |word| state_name.start_with?(word) }
end

#variant?(variant_name) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/docks/naming_conventions/suit_naming_convention.rb', line 36

def variant?(variant_name)
  variant_name.split("--").length > 1 && !state?(variant_name)
end