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

Methods included from Logger

#logger, logger, logger_setup

Constructor Details

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

Instance Attribute Details

#group_nameObject

Returns the value of attribute group_name.



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

def group_name
  @group_name
end

#group_pathObject

Returns the value of attribute group_path.



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

def group_path
  @group_path
end

#group_suffixObject

Returns the value of attribute group_suffix.



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

def group_suffix
  @group_suffix
end

#project_nameObject

Returns the value of attribute project_name.



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

def project_name
  @project_name
end

Instance Method Details

#generate_groupObject



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

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

#run!Object



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

def run!
  logger.info "Running: #{group_suffix}"
  generate_group

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

  # Print Created Groups/Project
  logger.info 'Group', name: @group.name, web_url: @group.web_url
  @projects.each do |project|
    logger.info 'Project', name: project.name, web_url: project.web_url
  end

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

#setupObject



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

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