class Embryo::Model::AuthenticatedGenerator

Public Instance Methods

install() click to toggle source
# File lib/generators/embryo/model/authenticated.rb, line 6
def install
  generate "embryo:model", ARGV.join(' ')
  generate "devise:install --quiet" unless File.exist? "config/initializers/devise.rb"
  generate "devise #{ARGV.first}"
  update_controllers
  update_factory
  update_seeds
end

Private Instance Methods

factory_additions() click to toggle source
# File lib/generators/embryo/model/authenticated.rb, line 39
      def factory_additions
'    sequence(:email) { |n| "user#{n}@example.com" }
    password "password"
'
      end
factory_name() click to toggle source
# File lib/generators/embryo/model/authenticated.rb, line 54
def factory_name
  file_path.gsub "/", "_"
end
seed_data() click to toggle source
# File lib/generators/embryo/model/authenticated.rb, line 49
      def seed_data
"\n" + class_name + '.where(email: "' + singular_name + '@example.com").first_or_create password: "password"
'
      end
update_controllers() click to toggle source
# File lib/generators/embryo/model/authenticated.rb, line 17
def update_controllers
  return if File.read("app/controllers/application_controller.rb").include? ":authenticate"
  inject_into_file "app/controllers/application_controller.rb", {
    after: "class ApplicationController < ActionController::Base\n"
  } do
    "  before_action :authenticate_#{singular_name}!\n\n"
  end
  inject_into_file "app/controllers/dashboard_controller.rb", {
    after: "class DashboardController < ApplicationController\n"
  } do
    "  skip_before_action :authenticate_#{singular_name}!\n\n"
  end
end
update_factory() click to toggle source
# File lib/generators/embryo/model/authenticated.rb, line 31
def update_factory
  inject_into_file "spec/factories/#{file_path}.rb", {
    after: /  factory :#{factory_name}.* do\n/
  } do
    factory_additions
  end
end
update_seeds() click to toggle source
# File lib/generators/embryo/model/authenticated.rb, line 45
def update_seeds
  append_file "db/seeds.rb", seed_data
end