Class: Kettle::Family::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/kettle/family/config.rb

Constant Summary collapse

DEFAULT_PATHS =
[".kettle-family.yml", ".structuredmerge/kettle-family.yml"].freeze
DEFAULT_MEMBER_EXCLUDES =
[
  "vendor/**",
  "**/vendor/**",
  "tmp/**",
  "**/tmp/**",
  "spec/**",
  "**/spec/**",
  "test/**",
  "**/test/**"
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root:, path:, data:) ⇒ Config

Returns a new instance of Config.



33
34
35
36
37
# File 'lib/kettle/family/config.rb', line 33

def initialize(root:, path:, data:)
  @root = root
  @path = path
  @data = stringify_keys(data)
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



20
21
22
# File 'lib/kettle/family/config.rb', line 20

def data
  @data
end

#pathObject (readonly)

Returns the value of attribute path.



20
21
22
# File 'lib/kettle/family/config.rb', line 20

def path
  @path
end

#rootObject (readonly)

Returns the value of attribute root.



20
21
22
# File 'lib/kettle/family/config.rb', line 20

def root
  @root
end

Class Method Details

.load(root:, path: nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/kettle/family/config.rb', line 22

def self.load(root:, path: nil)
  expanded_root = File.expand_path(root)
  config_path = path && File.expand_path(path, expanded_root)
  config_path ||= DEFAULT_PATHS
    .map { |candidate| File.join(expanded_root, candidate) }
    .find { |candidate| File.file?(candidate) }

  data = config_path ? YAML.load_file(config_path) : {}
  new(root: expanded_root, path: config_path, data: data || {})
end

Instance Method Details

#branch_lanesObject



133
134
135
# File 'lib/kettle/family/config.rb', line 133

def branch_lanes
  fetch_path("branch_lanes") || fetch_path("branches", "lanes") || {}
end

#command_for(name) ⇒ Object



89
90
91
# File 'lib/kettle/family/config.rb', line 89

def command_for(name)
  fetch_path("commands", name)
end

#discover_members?Boolean

Returns:

  • (Boolean)


70
71
72
73
# File 'lib/kettle/family/config.rb', line 70

def discover_members?
  members = data.fetch("members", {})
  members.fetch("discover", true)
end

#explicit_membersObject



60
61
62
63
64
65
66
67
68
# File 'lib/kettle/family/config.rb', line 60

def explicit_members
  members = data.fetch("members", {})
  explicit = members.fetch("explicit", [])
  explicit.map do |entry|
    entry = stringify_keys(entry)
    member_root = File.expand_path(entry.fetch("root"), root)
    entry.merge("root" => member_root)
  end
end

#family_modeObject



43
44
45
# File 'lib/kettle/family/config.rb', line 43

def family_mode
  fetch_path("family", "mode") || "monorepo"
end

#family_nameObject



39
40
41
# File 'lib/kettle/family/config.rb', line 39

def family_name
  fetch_path("family", "name") || File.basename(root)
end

#member_exclude_patternsObject



75
76
77
78
79
# File 'lib/kettle/family/config.rb', line 75

def member_exclude_patterns
  members = data.fetch("members", {})
  patterns = members.fetch("exclude", nil) || members.fetch("ignore", nil) || []
  DEFAULT_MEMBER_EXCLUDES + Array(patterns)
end

#member_rootsObject



52
53
54
55
56
57
58
# File 'lib/kettle/family/config.rb', line 52

def member_roots
  configured = fetch_path("members", "roots")
  return configured.map { |path| File.expand_path(path, root) } if configured
  return sibling_member_roots if family_mode == "sibling_repos"

  [members_root]
end

#members_rootObject



47
48
49
50
# File 'lib/kettle/family/config.rb', line 47

def members_root
  configured = fetch_path("family", "members_root") || fetch_path("members", "root")
  configured ? File.expand_path(configured, root) : root
end

#normalize_lockfiles?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'lib/kettle/family/config.rb', line 105

def normalize_lockfiles?
  fetch_path("template", "normalize_lockfiles") == true
end

#normalize_lockfiles_commandObject



109
110
111
# File 'lib/kettle/family/config.rb', line 109

def normalize_lockfiles_command
  fetch_path("template", "normalize_lockfiles_command") || "bundle lock"
end

#order_hintsObject



85
86
87
# File 'lib/kettle/family/config.rb', line 85

def order_hints
  fetch_path("members", "order", "hints") || []
end

#order_modeObject



81
82
83
# File 'lib/kettle/family/config.rb', line 81

def order_mode
  fetch_path("members", "order", "mode") || "dependency"
end

#release_build_commandObject



113
114
115
# File 'lib/kettle/family/config.rb', line 113

def release_build_command
  fetch_path("release", "build_command") || command_for("release_build") || "bundle exec rake build"
end

#release_publish_commandObject



117
118
119
# File 'lib/kettle/family/config.rb', line 117

def release_publish_command
  fetch_path("release", "publish_command") || command_for("release_publish") || "bundle exec kettle-release"
end

#release_push_commandObject



125
126
127
# File 'lib/kettle/family/config.rb', line 125

def release_push_command
  fetch_path("release", "push_command") || command_for("release_push") || "git push --follow-tags"
end

#release_tag_commandObject



121
122
123
# File 'lib/kettle/family/config.rb', line 121

def release_tag_command
  fetch_path("release", "tag_command") || command_for("release_tag") || "git tag"
end

#release_target_branchesObject



129
130
131
# File 'lib/kettle/family/config.rb', line 129

def release_target_branches
  fetch_path("release", "target_branches") || fetch_path("branches", "release_targets") || []
end

#template_commandObject



93
94
95
# File 'lib/kettle/family/config.rb', line 93

def template_command
  fetch_path("template", "command") || command_for("template")
end

#template_profileObject



97
98
99
# File 'lib/kettle/family/config.rb', line 97

def template_profile
  fetch_path("template", "profile")
end

#template_repository_topologyObject



101
102
103
# File 'lib/kettle/family/config.rb', line 101

def template_repository_topology
  fetch_path("template", "repository_topology")
end