Class: Draft::AccountGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Includes:
Rails::Generators::ResourceHelpers
Defined in:
lib/generators/draft/account/account_generator.rb

Instance Method Summary collapse

Instance Method Details

#create_root_folderObject



40
41
42
# File 'lib/generators/draft/account/account_generator.rb', line 40

def create_root_folder
  empty_directory File.join("app/views", "#{singular_table_name.underscore}_authentication")
end

#generate_before_actionsObject



32
33
34
# File 'lib/generators/draft/account/account_generator.rb', line 32

def generate_before_actions
  authentication_helpers
end

#generate_controllerObject



36
37
38
# File 'lib/generators/draft/account/account_generator.rb', line 36

def generate_controller
  template "controllers/authentication_controller.rb", "app/controllers/#{singular_table_name.underscore}_authentication_controller.rb"
end

#generate_modelObject



23
24
25
26
# File 'lib/generators/draft/account/account_generator.rb', line 23

def generate_model
  invoke "draft:model", paramaterize_attributes
  edit_model
end

#generate_required_attributesObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/generators/draft/account/account_generator.rb', line 12

def generate_required_attributes
  unless attributes_has_password_digest?
    password_digest = Rails::Generators::GeneratedAttribute.parse(["password_digest", :string, nil].compact.join(":"))
    attributes.unshift(password_digest)
  end
  unless attributes_has_email?
    email = Rails::Generators::GeneratedAttribute.parse(["email", :string, nil].compact.join(":"))
    attributes.unshift(email)
  end
end

#generate_routesObject



28
29
30
# File 'lib/generators/draft/account/account_generator.rb', line 28

def generate_routes
  authentication_routes
end

#generate_view_filesObject



44
45
46
47
48
49
# File 'lib/generators/draft/account/account_generator.rb', line 44

def generate_view_files
  available_views.each do |view|
    filename = view_authentication_filename_with_extensions(view)
    template filename, File.join("app/views/#{singular_table_name.underscore}_authentication", File.basename(filename))
  end
end