<commit_before>class AuthGenerator < Rails::Generators::NamedBase
  source_root File.expand_path('../templates', __FILE__)

  APP_NAME = Rails.application.class.parent.name

  APP_ROUTES_LINES =<<-EOS
  match '/auth/:provider/callback' => 'sessions#create'
  match "/signout" => "sessions#destroy", :as => :signout
  EOS

  APP_VIEW_LAYOUT_LINES =<<-EOS
  <% if current_user %>
    Welcome <%= current_user.name %>!
    <%= link_to "Sign Out", signout_path %>
  <% else %>
    <%= link_to "Sign in with Twitter", "/auth/twitter" %>
    <%= link_to "Sign in with Github", "/auth/github" %>
  <% end %>
  EOS

  APP_CONTROLLER_LINES =<<-EOS
  helper_method :current_user

  def current_user
    begin
      @current_user || User.find(session[:user_id]) if session[:user_id]
    rescue
      nil
    end
  end

  def authenticate
    redirect_to :root unless current_user
  end
  EOS

  def install
    # copy initializer
    copy_file "omniauth.rb", "config/initializers/omniauth.rb"
    # session_controllerに追加
    copy_file "sessions_controller.rb", "app/controllers/sessions_controller.rb"
    # application controllerに追加
    inject_into_class "app/controllers/application_controller.rb", ApplicationController, APP_CONTROLLER_LINES
    # add user_model
    copy_file "user.rb", "app/models/user.rb"
    # session_controllerに追加
    copy_file "migration_create_users.rb", "db/migrate/#{Time.now.strftime('%Y%m%d%H%M%S')}_create_user.rb"
    # application layout
    inject_into_file "app/views/layouts/application.html.erb", APP_VIEW_LAYOUT_LINES, :after => "<body>"
    inject_into_file "app/views/layouts/application.html.erb", APP_VIEW_LAYOUT_LINES, :after => "%body"
    # config/routes
    inject_into_file "config/routes.rb", APP_ROUTES_LINES, :after => "#{APP_NAME}::Application.routes.draw do\n"
  end
end<commit_msg>fix generator<commit_after>class AuthGenerator < Rails::Generators::NamedBase
  source_root File.expand_path('../templates', __FILE__)

  APP_NAME = Rails.application.class.parent.name

  APP_ROUTES_LINES =<<-EOS
  match '/auth/:provider/callback' => 'sessions#create'
  match "/signout" => "sessions#destroy", :as => :signout
  EOS

  APP_VIEW_LAYOUT_LINES =<<-EOS
  <% if current_user %>
    Welcome <%= current_user.name %>!
    <%= link_to "Sign Out", signout_path %>
  <% else %>
    <%= link_to "Sign in with Twitter", "/auth/twitter" %>
    <%= link_to "Sign in with Github", "/auth/github" %>
  <% end %>
  EOS

  APP_CONTROLLER_LINES =<<-EOS
  helper_method :current_user

  def current_user
    begin
      @current_user || User.find(session[:user_id]) if session[:user_id]
    rescue
      nil
    end
  end

  def authenticate
    redirect_to :root unless current_user
  end
  EOS

  def install
    # copy initializer
    copy_file "omniauth.rb", "config/initializers/omniauth.rb"
    # session_controllerに追加
    copy_file "sessions_controller.rb", "app/controllers/sessions_controller.rb"
    # application controllerに追加
    inject_into_class "app/controllers/application_controller.rb", ApplicationController, APP_CONTROLLER_LINES
    # add user_model
    copy_file "user.rb", "app/models/user.rb"
    # session_controllerに追加
    copy_file "migration_create_users.rb", "db/migrate/#{Time.now.strftime('%Y%m%d%H%M%S')}_create_users.rb"
    # application layout
    inject_into_file "app/views/layouts/application.html.erb", APP_VIEW_LAYOUT_LINES, :after => "<body>"
    inject_into_file "app/views/layouts/application.html.haml", APP_VIEW_LAYOUT_LINES, :after => "%body"
    # config/routes
    inject_into_file "config/routes.rb", APP_ROUTES_LINES, :after => "#{APP_NAME}::Application.routes.draw do\n"
  end
end
{'fraction_non_alphanumeric': 0.13088718510405256, 'fraction_numerical': 0.0, 'mean_word_length': 4.174220963172805, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6624078', 'n_tokens_mistral': 1330, 'n_tokens_neox': 1275, 'n_words': 228}