Module: HatiConfig::Team

Defined in:
lib/hati_config/team.rb

Overview

Team module provides functionality for managing team-specific configurations.

Instance Method Summary collapse

Instance Method Details

#[](team_name) ⇒ Module

Gets a specific team's configuration module.

Parameters:

  • team_name (Symbol) —

    The name of the team

Returns:

  • (Module) —

    The team's configuration module

Raises:

  • (NameError) —

    If the team does not exist



47
48
49
# File 'lib/hati_config/team.rb', line 47

def [](team_name)
  const_get(team_name.to_s.capitalize)
end

#remove_team?(team_name) ⇒ Boolean

Removes a team's configuration.

Parameters:

  • team_name (Symbol) —

    The name of the team

Returns:

  • (Boolean) —

    True if the team was removed



63
64
65
66
67
68
69
# File 'lib/hati_config/team.rb', line 63

def remove_team?(team_name)
  const_name = team_name.to_s.capitalize
  return false unless const_defined?(const_name)

  remove_const(const_name)
  true
end

#team(team_name) { ... } ⇒ Object

Defines team-specific configuration namespace.

Examples:

team :frontend do
  configure :settings do
    config api_endpoint: '/api/v1'
    config cache_ttl: 300
  end
end

Parameters:

  • team_name (Symbol) —

    The name of the team (e.g., :frontend, :backend, :mobile)

Yields:

  • The configuration block for the team



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/hati_config/team.rb', line 17

def team(team_name, &block)
  team_module = Module.new do
    extend HatiConfig::Configuration
    extend HatiConfig::Environment
  end

  const_name = team_name.to_s.capitalize
  const_set(const_name, team_module)
  team_module.instance_eval(&block) if block_given?

  # Define method for accessing team module
  singleton_class.class_eval do
    define_method(team_name) { const_get(const_name) }
  end

  team_module
end

#team?(team_name) ⇒ Boolean

Checks if a team exists.

Parameters:

  • team_name (Symbol) —

    The name of the team

Returns:

  • (Boolean) —

    True if the team exists



55
56
57
# File 'lib/hati_config/team.rb', line 55

def team?(team_name)
  const_defined?(team_name.to_s.capitalize)
end

#teams ⇒ Array<Symbol>

Gets a list of all defined teams.

Returns:

  • (Array<Symbol>) —

    The list of team names



38
39
40
# File 'lib/hati_config/team.rb', line 38

def teams
  constants.select { |c| const_get(c).is_a?(Module) && const_get(c).respond_to?(:configure) }
end

#with_team(team_name) { ... } ⇒ Object

Temporarily switches to a team's configuration context.

Examples:

with_team(:frontend) do
  # Configuration will use frontend team's context here
end

Parameters:

  • team_name (Symbol) —

    The name of the team

Yields:

  • The block to execute in the team's context

Raises:

  • (NameError)


79
80
81
82
83
# File 'lib/hati_config/team.rb', line 79

def with_team(team_name)
  raise NameError, "Team '#{team_name}' does not exist" unless team?(team_name)

  yield self[team_name]
end