Class: AnnFlavorCocoapods::SpecLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/ann_flavor_cocoapods/spec_loader.rb

Constant Summary collapse

SPEC_FILE =
'annspec.yaml'

Class Method Summary collapse

Class Method Details

.enabled?(spec) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/ann_flavor_cocoapods/spec_loader.rb', line 29

def self.enabled?(spec)
  spec.fetch('enabled', true) != false
end

.find_spec_file(start_dir) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ann_flavor_cocoapods/spec_loader.rb', line 17

def self.find_spec_file(start_dir)
  dir = File.expand_path(start_dir)
  loop do
    candidate = File.join(dir, SPEC_FILE)
    return candidate if File.exist?(candidate)
    parent = File.dirname(dir)
    break if parent == dir
    dir = parent
  end
  nil
end

.ios_default(spec) ⇒ Object



38
39
40
41
# File 'lib/ann_flavor_cocoapods/spec_loader.rb', line 38

def self.ios_default(spec)
  return {} unless enabled?(spec)
  spec.dig('app', 'ios', 'default') || {}
end

.ios_flavors(spec) ⇒ Object



33
34
35
36
# File 'lib/ann_flavor_cocoapods/spec_loader.rb', line 33

def self.ios_flavors(spec)
  return {} unless enabled?(spec)
  spec.dig('app', 'ios', 'flavor') || {}
end

.load(project_root = nil) ⇒ Object

Parsing itself is delegated to ann-flavor-core-ruby (ADR-008) — this class loads the raw YAML for callers that still want Hash-shaped access (e.g. an end user's Podfile), and PodfileHelper additionally parses through the core for cascade resolution.



11
12
13
14
15
# File 'lib/ann_flavor_cocoapods/spec_loader.rb', line 11

def self.load(project_root = nil)
  path = find_spec_file(project_root || Dir.pwd)
  raise "annspec.yaml not found (searched upward from #{project_root || Dir.pwd})" unless path
  YAML.safe_load(File.read(path), permitted_classes: [Symbol])
end