Class: Auth::Generators::ControllersGenerator

Inherits:
Rails::Generator::NamedBase
  • Object
show all
Defined in:
lib/auth/generators/controllers_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, options = {}) ⇒ ControllersGenerator

Returns a new instance of ControllersGenerator.



4
5
6
7
8
# File 'lib/auth/generators/controllers_generator.rb', line 4

def initialize(model, options = {})
  @model = model
  args = [ model.name ]
  super(args, options)
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



2
3
4
# File 'lib/auth/generators/controllers_generator.rb', line 2

def model
  @model
end

Instance Method Details

#manifestObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/auth/generators/controllers_generator.rb', line 10

def manifest
  record do |m|
    m.directory "app/controllers"
    m.directory "app/helpers"
    
    m.template "accounts_controller.rb", File.join("app/controllers", "#{model.accounts_controller.underscore}_controller.rb"),
               :assigns => { :model => model }
    m.template "sessions_controller.rb", File.join("app/controllers", "#{model.sessions_controller.underscore}_controller.rb"),
               :assigns => { :model => model }
    
    m.template "accounts_helper.rb", File.join("app/helpers", "#{model.accounts_controller.underscore}_helper.rb"),
               :assigns => { :model => model }
    m.template "sessions_helper.rb", File.join("app/helpers", "#{model.sessions_controller.underscore}_helper.rb"),
               :assigns => { :model => model }
    
    # Controller generator should also kick off the corresponding view generation.
    views = Auth::Generators::ViewsGenerator.new(model, :source => File.join(source_root), :destination => destination_root)
    views.manifest.replay(m)
  end
end

#specObject



31
32
33
# File 'lib/auth/generators/controllers_generator.rb', line 31

def spec
  @spec ||= Rails::Generator::Spec.new("controllers", File.join(Auth.path, "auth/generators"), nil)
end