Class: Ace::Bundle::Atoms::BundleNormalizer

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/bundle/atoms/bundle_normalizer.rb

Overview

Normalizes bundle configuration into ace-bundle compatible structure

Handles various input formats and ensures proper structure for ace-bundle:

  • String inputs (preset names) wrapped in bundle.presets array

  • Hashes with top-level base: key moved to bundle.base

  • Hashes with both base: and bundle: keys properly merged

  • Properly structured configs passed through unchanged

  • Normalizes all input to bundle: key structure for ace-bundle compatibility

Class Method Summary collapse

Class Method Details

.merge_base_into_bundle(input) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Merge top-level base into existing bundle.base

Parameters:

  • input (Hash)

    Configuration with both base and bundle keys

Returns:

  • (Hash)

    Configuration with base merged into bundle



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/ace/bundle/atoms/bundle_normalizer.rb', line 104

def self.merge_base_into_bundle(input)
  normalized = {}
  base_value = input["base"] || input[:base]

  input.each do |key, value|
    key_str = key.to_s
    if key_str == "base"
      # Skip - will add under bundle.base below
      next
    elsif key_str == "bundle"
      # Merge base value into existing bundle
      bundle_hash = value.is_a?(Hash) ? value.dup : {}
      bundle_hash["base"] = base_value
      normalized["bundle"] = bundle_hash
    else
      normalized[key_str] = value
    end
  end

  normalized
end

.normalize_config(input) ⇒ Hash

Normalize various input types to proper ace-bundle structure

Examples:

String input (preset name)

normalize_config("project")
#=> { "bundle" => { "presets" => ["project"] } }

Hash with top-level base key

normalize_config({ "base" => "custom content", "files" => ["README.md"] })
#=> { "bundle" => { "base" => "custom content", "files" => ["README.md"] } }

Hash with both base and bundle keys

normalize_config({ "base" => "content", "bundle" => { "presets" => ["project"] } })
#=> { "bundle" => { "base" => "content", "presets" => ["project"] } }

Properly structured config (unchanged)

normalize_config({ "bundle" => { "base" => "content" } })
#=> { "bundle" => { "base" => "content" } }

Parameters:

  • input (String, Hash, nil)

    Bundle configuration input

Returns:

  • (Hash)

    Normalized bundle configuration



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/ace/bundle/atoms/bundle_normalizer.rb', line 36

def self.normalize_config(input)
  case input
  when String
    # String input (e.g., "project", "staged") -> wrap as preset
    {"bundle" => {"presets" => [input]}}
  when Hash
    normalize_hash_config(input)
  when NilClass
    # Return empty config for nil
    {}
  else
    # Fallback for unexpected types
    {}
  end
end

.normalize_hash_config(input) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Normalize hash-based bundle configuration

Parameters:

  • input (Hash)

    Bundle configuration hash

Returns:

  • (Hash)

    Normalized configuration



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/ace/bundle/atoms/bundle_normalizer.rb', line 57

def self.normalize_hash_config(input)
  # Check if this config has a top-level "base" key that needs to be moved
  has_base = input.key?("base") || input.key?(:base)
  # Check for bundle: configuration key
  has_bundle_config = input.key?("bundle") || input.key?(:bundle)

  if has_base && !has_bundle_config
    # Case 1: Config has base: at top level but no bundle: key
    # Need to move base under bundle.base and wrap other keys
    wrap_base_in_bundle(input)
  elsif has_base && has_bundle_config
    # Case 2: Config has both base: and bundle: at top level
    # Move base under bundle.base
    merge_base_into_bundle(input)
  else
    # Case 3: Config already properly structured or doesn't need normalization
    input
  end
end

.wrap_base_in_bundle(input) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Wrap top-level base and other keys under bundle

Parameters:

  • input (Hash)

    Configuration with top-level base

Returns:

  • (Hash)

    Configuration with base under bundle.base



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/ace/bundle/atoms/bundle_normalizer.rb', line 82

def self.wrap_base_in_bundle(input)
  normalized = {"bundle" => {}}

  input.each do |key, value|
    key_str = key.to_s
    if key_str == "base"
      # Move top-level base to bundle.base
      normalized["bundle"]["base"] = value
    else
      # Other top-level keys go under bundle
      normalized["bundle"][key_str] = value
    end
  end

  normalized
end