module Jobshop module Generators class TeamGenerator < Rails::Generators::NamedBase source_root File.expand_path("../templates", __FILE__) desc "Create a jobshop team." attr_reader :team, :link_text, :first_team def require_environment ENV['RAILS_ENV'] ||= "development" abort "Please run this command within a Rails app." unless Rails.root environment_filename = File.expand_path( Rails.root + "config/environment.rb") require environment_filename end def create_team @team = Jobshop::Team.create!(name: name) end def generate_token @token = team.generate_registration_token end def generate_secure_registration_link link_protocol = Rails.env.development? ? "http" : "https" link_host = Rails.env.development? ? "localhost:3000" : "YOUR-HOST-NAME" # TODO: Give environments besides development a decent host and # protocol. HTTPS isn't mandatory in production but it is very, VERY # highly recommended. @link_text = Jobshop::Engine.routes.url_helpers. new_team_registration_url(@team, protocol: link_protocol, host: link_host, registration_token: @token ) end def print_secure_registration_link say <<-MESSAGE ### JOBSHOP - IMPORTANT INFORMATION ############################################ Your Jobshop team "#{name}" has been initialized. You may use the following link to complete the setup process. #{link_text} This link is valid for 30 minutes from now and will expire at: #{30.minutes.from_now.in_time_zone("Eastern Time (US & Canada)")} Thank you for using Jobshop! ################################################################################ MESSAGE end end end end