Class: ComponentGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/component/component_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_componentObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/generators/component/component_generator.rb', line 4

def add_component
  segments = name.underscore.split('/')
  fail("NAME must be of the form Family::ComponentName or family/component_name but got #{name.inspect}") if segments.size != 2
  @family, @comp = segments
  @family = @family.pluralize # Force plural
  @family_cst = @family.camelize.pluralize # Force plural
  @comp_cst = @comp.camelize # Tolerate singular and plural
  @args = args

  case @comp_cst
  when 'Destroy'
    template 'destroy.rb.erb', "app/components/#{@family}/#{@comp}.rb"
  when 'Edit'
    template 'edit.rb.erb', "app/components/#{@family}/#{@comp}.rb"
  when 'Form'
    template 'form.rb.erb', "app/components/#{@family}/#{@comp}.rb"
  when 'New'
    template 'new.rb.erb', "app/components/#{@family}/#{@comp}.rb"
  else
    template 'component.rb.erb', "app/components/#{@family}/#{@comp}.rb"
  end
end