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



62
63
64
65
66
67
68
69
70
# File 'lib/cocoapods-bb-PodAssistant/helpers/yaml_files_helper.rb', line 62

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_local_stable_podlock(yml_path, pod_targets) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/cocoapods-bb-PodAssistant/helpers/yaml_files_helper.rb', line 47

def self.save_local_stable_podlock(yml_path, pod_targets)
    yamlData = read_stable_lock_yaml(yml_path)
    if yamlData.is_a? Hash
        pod_targets.map { |pod_target|
            name = pod_target.pod_name
            yamlData[name] = pod_target.root_spec.version.version
        }
        save_stable_lock_yaml(yml_path, yamlData)
    end
end

.save_stable_lock_yaml(yml_path, pod_jsondata) ⇒ Object



58
59
60
# File 'lib/cocoapods-bb-PodAssistant/helpers/yaml_files_helper.rb', line 58

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
46
# 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