Sha256: 6fefc6b4f19179ca64ac11b4655a04b205323dab9b8fa504b4eb6ee9ade51821

Contents?: true

Size: 1.79 KB

Versions: 2

Compression:

Stored size: 1.79 KB

Contents

module Jobshop
  module Generators
    class TeamGenerator < Rails::Generators::Base
      source_root File.expand_path("../templates", __FILE__)

      desc "Create a jobshop 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.new
      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.
        @secure_url = ::Jobshop::Engine.routes.url_helpers.
          new_welcome_registration_url(
          protocol: link_protocol,
          host: link_host,
          registration_token: @token,
          team_id: @team.id
        )
      end

      def print_secure_registration_link
        say <<-MESSAGE
### JOBSHOP - IMPORTANT INFORMATION ############################################

      Your Jobshop team has been initialized.
      You may use the following link to complete the setup process.

      #{@secure_url}

      This link is valid for 30 minutes 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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
jobshop-0.0.131 lib/generators/jobshop/team/team_generator.rb
jobshop-0.0.127 lib/generators/jobshop/team/team_generator.rb