Class: AppEntitlementsStatistics::Extracter

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Helper::Sigflat, Helper::Utils
Defined in:
lib/cocoapods-entitlements-statistics/app_entitlements_statistics/extracter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper::Utils

#defalut_store_path, #entitlements_yaml_name, #report_file_name, #versions_yaml_name

Methods included from Helper::Sigflat

#createsig

Constructor Details

#initialize(args) ⇒ Extracter

Returns a new instance of Extracter.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/cocoapods-entitlements-statistics/app_entitlements_statistics/extracter.rb', line 24

def initialize(args)
    args.each do |key ,value|
        case key
        when "cur_version"
            @cur_version = value
        when "product_bundle_identifier"
            @identifier = value
        when "info_plist_path"
            @info_plist_path = value
        when "entitlements_path"
            @entitlements_path = value
        when "system_capabilities"
            @system_capabilities = value
        end
    end
end

Instance Attribute Details

#cur_versionObject (readonly)

Returns the value of attribute cur_version.



22
23
24
# File 'lib/cocoapods-entitlements-statistics/app_entitlements_statistics/extracter.rb', line 22

def cur_version
  @cur_version
end

#entitlements_pathObject (readonly)

Returns the value of attribute entitlements_path.



20
21
22
# File 'lib/cocoapods-entitlements-statistics/app_entitlements_statistics/extracter.rb', line 20

def entitlements_path
  @entitlements_path
end

#identifierObject (readonly)

Returns the value of attribute identifier.



21
22
23
# File 'lib/cocoapods-entitlements-statistics/app_entitlements_statistics/extracter.rb', line 21

def identifier
  @identifier
end

#info_plist_pathObject (readonly)

Returns the value of attribute info_plist_path.



19
20
21
# File 'lib/cocoapods-entitlements-statistics/app_entitlements_statistics/extracter.rb', line 19

def info_plist_path
  @info_plist_path
end

#system_capabilitiesObject (readonly)

Returns the value of attribute system_capabilities.



18
19
20
# File 'lib/cocoapods-entitlements-statistics/app_entitlements_statistics/extracter.rb', line 18

def system_capabilities
  @system_capabilities
end

Instance Method Details

#entitlementsInfoObject



106
107
108
# File 'lib/cocoapods-entitlements-statistics/app_entitlements_statistics/extracter.rb', line 106

def entitlementsInfo
    @entitlementsInfo ||= EntitlementsPlist.new(@entitlements_path)
end

#extract_capabilities_infoObject



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/cocoapods-entitlements-statistics/app_entitlements_statistics/extracter.rb', line 81

def extract_capabilities_info 
    #{"com.apple.BackgroundModes"=>{"enabled"=>"1"}, "com.apple.InAppPurchase"=>{"enabled"=>"1"}, "com.apple.Push"=>{"enabled"=>"1"}}
    capabilities_info = {}

    @system_capabilities.each do |key,value|
        case key
        when  "com.apple.InAppPurchase"
            capabilities_info["In-App Purchase"] = { key => value }
        when "com.apple.BackgroundModes"
            h1 = {key => value}
            h2 = plistInfo.backgroundModes["Background Modes"]
            capabilities_info["Background Modes"] = h1.merge(h2)
        when "com.apple.Push"
            capabilities_info["Push Notifications"] = { key => value }
        end    
    end 
    capabilities_info = capabilities_info.merge(entitlementsInfo.enabled_capabilities)
    capabilities_info = capabilities_info.merge(plistInfo.enabled_capabilities)
    capabilities_info
end

#extract_updateObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/cocoapods-entitlements-statistics/app_entitlements_statistics/extracter.rb', line 41

def extract_update            
    capabilities_summary = Hash.new
    capabilities = extract_capabilities_info
    capabilities.each do |key,value|
        capabilities_summary[key] = createsig(value)
    end

    usage_desc_summary = Hash.new
    usage_desc = plistInfo.permis_usagedescription
    usage_desc.each do |key,value|
        usage_desc_summary[key] = createsig(value)
    end

    yaml_content = {
        'Capabilities_Summary' => capabilities_summary,
        'Capabilities' => capabilities,
        'PermissionsUsageDescription_Summary' => usage_desc_summary,
        'PermissionsUsageDescription' => usage_desc
    }
    yaml_name = entitlements_yaml_name(@cur_version, @identifier , path: @store_path)

    File.open(yaml_name, "w") { |file| file.write(yaml_content.to_yaml) }
    update_versions
    yaml_content
end

#plistInfoObject



102
103
104
# File 'lib/cocoapods-entitlements-statistics/app_entitlements_statistics/extracter.rb', line 102

def plistInfo
    @plistInfo ||= InfoPlist.new(@info_plist_path)
end

#update_versionsObject



68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/cocoapods-entitlements-statistics/app_entitlements_statistics/extracter.rb', line 68

def update_versions
    yaml_name = versions_yaml_name(@identifier , path: @store_path)
    yaml_content = [ ]
    if File.exist?(yaml_name) 
        yaml_content = YAML.load_file(yaml_name)
    end
    version = @cur_version
    if !yaml_content.include?(version)
        yaml_content.unshift(version)
        File.open(yaml_name, "w") { |file| file.write(yaml_content.to_yaml) }  
    end
end