Class: BB::YamlFilesHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods-bb-PodAssistant/helpers/yaml_files_helper.rb

Class Method Summary collapse

Class Method Details

.read_stable_lock_yaml(yml_path) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'lib/cocoapods-bb-PodAssistant/helpers/yaml_files_helper.rb', line 51

def self.read_stable_lock_yaml(yml_path)
    if File.file?(yml_path)
        # puts "read yaml path:#{yml_path}"
        json = YAML.load_file(yml_path)
        # puts "read json:#{json}"
        return json
    end
    return {}
end

.save_stable_lock_yaml(yml_path, pod_jsondata) ⇒ Object



47
48
49
# File 'lib/cocoapods-bb-PodAssistant/helpers/yaml_files_helper.rb', line 47

def self.save_stable_lock_yaml(yml_path, pod_jsondata)
    File.open(yml_path,"w") { |f| YAML.dump(pod_jsondata, f) }
end

.save_stable_podlock(yml_path, pod_targets) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/cocoapods-bb-PodAssistant/helpers/yaml_files_helper.rb', line 14

def self.save_stable_podlock(yml_path, pod_targets)
    yamlData = read_stable_lock_yaml(yml_path)
    # test data
    # yamlData[YAML_CONFIG_REMOVE_KEY] = ["AFNetworking"]
    # yamlData[YAML_CONFIG_DEPENDENCIES_KEY] = {"BBNativeContainer":["BBSchemeDispatcher","BBComponentServicesKit"]}
    if yamlData.is_a? Hash
        listdata = yamlData[YAML_CONFIG_LIST_KEY]
        removedata = yamlData[YAML_CONFIG_REMOVE_KEY]
        dependenciesdata = yamlData[YAML_CONFIG_DEPENDENCIES_KEY]
    else 
        yamlData = {}
    end
    if listdata.nil?
        listdata = {}
    end
    if removedata.nil?
        removedata = []
    end
    if dependenciesdata.nil?
        dependenciesdata = {}
    end
    pod_targets.map { |pod_target|
        name = pod_target.pod_name
        listdata[name] = pod_target.root_spec.version.version
        # 策略:列表存在数据需要删除移除数据
        removedata.delete(name)
    }
    yamlData[YAML_CONFIG_LIST_KEY] = listdata
    yamlData[YAML_CONFIG_REMOVE_KEY] = removedata
    yamlData[YAML_CONFIG_DEPENDENCIES_KEY] = dependenciesdata
    save_stable_lock_yaml(yml_path, yamlData)
end