Class: CocoapodsPodfileLocal::OverrideManager

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods_podfile_local/override_manager.rb

Overview

单例:在「解析 Podfile.local」与「prepend 后的 pod 方法」之间共享覆盖表。

Constant Summary collapse

SOURCE_KEYS =

表示「依赖来源」的三类主键,与 CocoaPods pod 声明一致(与下方互斥规则对应)。

%i[git path podspec].freeze
GIT_EXTRAS =

依附于 :git 的附加字段;与 path/podspec 来源互斥时一并清理。

%i[branch tag commit].freeze
EXCLUSIVE_RULES =

当 edit 指定某一来源时,应从「原 Podfile 选项」里删掉的冲突键,避免 path 与 git 等同时存在。

{
  git:     %i[path podspec],
  path:    %i[git branch tag commit podspec],
  podspec: %i[git branch tag commit path],
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOverrideManager

Returns a new instance of OverrideManager.



25
26
27
# File 'lib/cocoapods_podfile_local/override_manager.rb', line 25

def initialize
  @overrides = {}
end

Class Method Details

.instanceObject



16
17
18
# File 'lib/cocoapods_podfile_local/override_manager.rb', line 16

def self.instance
  @instance ||= new
end

.reset!Object

测试或多次加载场景下可清空单例(一般 pod install 单次进程不需要)。



21
22
23
# File 'lib/cocoapods_podfile_local/override_manager.rb', line 21

def self.reset!
  @instance = nil
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/cocoapods_podfile_local/override_manager.rb', line 37

def empty?
  @overrides.empty?
end

#merge(original_options, override_options) ⇒ Object

先把原 Hash 里与「新来源」冲突的键删掉,再 merge 覆盖项;覆盖键优先,其余保留原 Podfile。



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/cocoapods_podfile_local/override_manager.rb', line 42

def merge(original_options, override_options)
  merged = original_options.dup

  keys_to_remove = []
  EXCLUSIVE_RULES.each do |source_key, conflicting_keys|
    if override_options.key?(source_key)
      keys_to_remove.concat(conflicting_keys)
    end
  end

  keys_to_remove.uniq.each { |k| merged.delete(k) }
  merged.merge(override_options)
end

#overridesObject



33
34
35
# File 'lib/cocoapods_podfile_local/override_manager.rb', line 33

def overrides
  @overrides.dup
end

#register(pod_name, options) ⇒ Object



29
30
31
# File 'lib/cocoapods_podfile_local/override_manager.rb', line 29

def register(pod_name, options)
  @overrides[pod_name] = options
end