class VersionFile
.version file representation, see Carthage documentation on them: github.com/Carthage/Carthage/blob/master/Documentation/VersionFile.md
Attributes
frameworks_by_platform[R]
json[R]
path[R]
platforms[R]
version[R]
Public Class Methods
new(path, platforms = PLATFORMS)
click to toggle source
# File lib/version_file.rb, line 9 def initialize(path, platforms = PLATFORMS) @path = path @platforms = platforms parse end
Public Instance Methods
framework_names()
click to toggle source
Unique array of framework names.
# File lib/version_file.rb, line 35 def framework_names @frameworks_by_platform.values.flatten.uniq.sort end
move_to_build_dir()
click to toggle source
# File lib/version_file.rb, line 44 def move_to_build_dir basename = File.basename(@path) target_path = File.join(CARTHAGE_BUILD_DIR, basename) FileUtils.mv(@path, target_path) @path = target_path end
number_of_frameworks()
click to toggle source
Total number of frameworks accross all platforms.
# File lib/version_file.rb, line 40 def number_of_frameworks @frameworks_by_platform.values.flatten.count end
platforms_by_framework()
click to toggle source
Returns a Hash, e.g. “` {
"CocoaLumberjack" => [:iOS, :watchOS], "Lottie" => [:iOS],
} “`
# File lib/version_file.rb, line 22 def platforms_by_framework result = Hash.new { |h, k| h[k] = [] } for framework_name in framework_names @frameworks_by_platform.each do |platform, framework_names_in_platform| if framework_names_in_platform.include?(framework_name) result[framework_name] << platform end end end result end
remove()
click to toggle source
# File lib/version_file.rb, line 51 def remove FileUtils.rm(@path) end
same_content?(other_version_file)
click to toggle source
# File lib/version_file.rb, line 55 def same_content?(other_version_file) if other_version_file.nil? false else @json == other_version_file.json end end
Private Instance Methods
parse()
click to toggle source
# File lib/version_file.rb, line 65 def parse raise VersionFileDoesNotExistError.new, "File #{path} doesn't exist, has carthage been bootstrapped?" unless File.exist?(@path) @json = read_json @version = @json["commitish"] raise AppError.new, "Version is missing in #{@path}:\n\n#{@json}" if @version.nil? || @version.empty? @frameworks_by_platform = PLATFORMS.to_h { |platform| [platform, parse_platform(platform)] } end
parse_platform(platform)
click to toggle source
# File lib/version_file.rb, line 93 def parse_platform(platform) carthage_platform_name = platform_to_carthage_dir_string(platform) array = @json[carthage_platform_name] if array.kind_of?(Array) array.map { |entry| entry["name"] } else [] end end
read_json()
click to toggle source
Reads json from `@path` and cleans up entries, tha are not defined in `@platforms`.
# File lib/version_file.rb, line 77 def read_json file = File.read(@path) json = JSON.parse(file) stripped_json = strip_platforms(json) stripped_json end
strip_platforms(json)
click to toggle source
# File lib/version_file.rb, line 84 def strip_platforms(json) for platform in PLATFORMS if !@platforms.include?(platform) json[platform_to_carthage_dir_string(platform)] = [] end end json end