Class: LabClient::Generator::GroupTemplateHelper

Inherits:
TemplateHelper show all
Includes:
Names
Defined in:
lib/labclient/generator/template_helper.rb

Overview

Helper for Common Group/Project Templates

  • Create Group, @group

  • Execute any ‘setup_` methods

  • Print all @projects, and @group

Direct Known Subclasses

Environments, Pages, PipelineTrigger

Instance Attribute Summary collapse

Attributes inherited from TemplateHelper

#client, #opts

Instance Method Summary collapse

Methods included from Names

#create_file, #gen_description, #gen_groups, #gen_people, #gen_projects, #generate_names

Methods inherited from TemplateHelper

#initialize, #inspect

Constructor Details

This class inherits a constructor from LabClient::Generator::TemplateHelper

Instance Attribute Details

#group_nameObject

Returns the value of attribute group_name.



46
47
48
# File 'lib/labclient/generator/template_helper.rb', line 46

def group_name
  @group_name
end

#group_pathObject

Returns the value of attribute group_path.



46
47
48
# File 'lib/labclient/generator/template_helper.rb', line 46

def group_path
  @group_path
end

#group_suffixObject

Returns the value of attribute group_suffix.



46
47
48
# File 'lib/labclient/generator/template_helper.rb', line 46

def group_suffix
  @group_suffix
end

#project_nameObject

Returns the value of attribute project_name.



46
47
48
# File 'lib/labclient/generator/template_helper.rb', line 46

def project_name
  @project_name
end

Instance Method Details

#generate_groupObject



75
76
77
78
# File 'lib/labclient/generator/template_helper.rb', line 75

def generate_group
  @group = client.groups.create(name: group_name, path: group_path)
  raise 'Unable to Create Group' unless @group.success?
end

#run!Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/labclient/generator/template_helper.rb', line 48

def run!
  puts "Running: #{group_suffix}"
  generate_group

  # Run `setup_` prefixed classes
  self.class.instance_methods.grep(/setup_/).each { |x| send(x) }

  # Print Created Groups/Project
  puts "#{@group.name} - #{@group.web_url}"
  @projects.each do |project|
    puts " - #{project.name} - #{project.web_url}"
  end

  {
    group: @group,
    projects: @projects
  }
end

#setupObject



67
68
69
70
71
72
73
# File 'lib/labclient/generator/template_helper.rb', line 67

def setup
  self.group_suffix = self.class.name.demodulize
  self.group_name = opts[:group_name] || "#{gen_groups.sample} #{group_suffix}"
  self.group_path = opts[:group_path] || group_name.downcase.gsub(' ', '-')

  @projects = []
end