Class: Charming::Generators::Name

Inherits:
Object
  • Object
show all
Defined in:
lib/charming/generators/name.rb

Constant Summary collapse

VALID_NAME =
/\A[a-z][a-z0-9_]*\z/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Name

Returns a new instance of Name.

Raises:



10
11
12
13
# File 'lib/charming/generators/name.rb', line 10

def initialize(value)
  @snake_name = value.to_s
  raise Error, "Invalid name: #{value}" unless VALID_NAME.match?(@snake_name)
end

Instance Attribute Details

#snake_nameObject (readonly)

Returns the value of attribute snake_name.



8
9
10
# File 'lib/charming/generators/name.rb', line 8

def snake_name
  @snake_name
end

Instance Method Details

#class_nameObject



15
16
17
# File 'lib/charming/generators/name.rb', line 15

def class_name
  snake_name.split("_").map(&:capitalize).join
end

#component_class_nameObject



27
28
29
# File 'lib/charming/generators/name.rb', line 27

def component_class_name
  "#{class_name}Component"
end

#controller_class_nameObject



19
20
21
# File 'lib/charming/generators/name.rb', line 19

def controller_class_name
  "#{class_name}Controller"
end

#view_class_nameObject



23
24
25
# File 'lib/charming/generators/name.rb', line 23

def view_class_name
  "#{class_name}View"
end