Class: Padrino::Generators::Decorator

Inherits:
Thor::Group
  • Object
show all
Includes:
Actions, Thor::Actions
Defined in:
lib/generators/decorator.rb

Overview

Responsible for the generating decorators and associated tests within a Padrino application.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Actions

#apply_test_component_for_decorator_by

Class Method Details

Defines the banner for this CLI generator



16
# File 'lib/generators/decorator.rb', line 16

def self.banner; "padrino-gen decorator [name]"; end

.source_rootObject

Define the source template root



14
# File 'lib/generators/decorator.rb', line 14

def self.source_root; File.expand_path(File.dirname(__FILE__)); end

Instance Method Details

#create_decoratorObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Execute decorator generation



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/generators/decorator.rb', line 36

def create_decorator
  self.destination_root = options[:root]

  if in_app_root?
    app = options[:app]
    check_app_existence(app)
    inject_into_file(destination_root(app, "app.rb"), "    register Padrino::Decorator::Helpers\n", :after => "Padrino::Application\n")
    self.behavior = :revoke if options[:destroy]
    @object_name  = name.to_s.underscore
    @project_name = options[:namespace].underscore.camelize
    @project_name = fetch_project_name(app) if @project_name.empty?
    @app_name     = fetch_app_name(app)
    template 'templates/decorator.rb.tt', destination_root(app, 'decorators', "#{@object_name}_decorator.rb")
    if test?
      choice = fetch_component_choice(:test)
      apply_test_component_for_decorator_by choice
      generate_decorator_test(name)
    end
  else
    say 'You are not at the root of a Padrino application! (config/boot.rb not found)'
  end
end