Module: HatiConfig::Team
- Defined in:
- lib/hati_config/team.rb
Overview
Team module provides functionality for managing team-specific configurations.
Instance Method Summary collapse
-
#[](team_name) ⇒ Module
Gets a specific team's configuration module.
-
#remove_team?(team_name) ⇒ Boolean
Removes a team's configuration.
-
#team(team_name) { ... } ⇒ Object
Defines team-specific configuration namespace.
-
#team?(team_name) ⇒ Boolean
Checks if a team exists.
-
#teams ⇒ Array<Symbol>
Gets a list of all defined teams.
-
#with_team(team_name) { ... } ⇒ Object
Temporarily switches to a team's configuration context.
Instance Method Details
#[](team_name) ⇒ Module
Gets a specific team's configuration module.
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.
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.
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.
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.
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.
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 |