Class: Jobshop::Generators::TeamGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/jobshop/team/team_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#first_teamObject (readonly)

Returns the value of attribute first_team.



8
9
10
# File 'lib/generators/jobshop/team/team_generator.rb', line 8

def first_team
  @first_team
end

Returns the value of attribute link_text.



8
9
10
# File 'lib/generators/jobshop/team/team_generator.rb', line 8

def link_text
  @link_text
end

#teamObject (readonly)

Returns the value of attribute team.



8
9
10
# File 'lib/generators/jobshop/team/team_generator.rb', line 8

def team
  @team
end

Instance Method Details

#create_teamObject



20
21
22
# File 'lib/generators/jobshop/team/team_generator.rb', line 20

def create_team
  @team = ::Jobshop::Team.create!(name: name)
end


28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/generators/jobshop/team/team_generator.rb', line 28

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

#generate_tokenObject



24
25
26
# File 'lib/generators/jobshop/team/team_generator.rb', line 24

def generate_token
  @token = team.generate_registration_token
end


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/generators/jobshop/team/team_generator.rb', line 42

def print_secure_registration_link
  say "### JOBSHOP - IMPORTANT INFORMATION ############################################\n\nYour Jobshop team \"\#{name}\" has been initialized.\nYou may use the following link to complete the setup process.\n\n\#{link_text}\n\nThis link is valid for 30 minutes from now and will expire at:\n\#{30.minutes.from_now.in_time_zone(\"Eastern Time (US & Canada)\")}\n\nThank you for using Jobshop!\n\n################################################################################\n  MESSAGE\nend\n"

#require_environmentObject



10
11
12
13
14
15
16
17
18
# File 'lib/generators/jobshop/team/team_generator.rb', line 10

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