Class: VersionFile

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

Overview

.version file representation, see Carthage documentation on them: github.com/Carthage/Carthage/blob/master/Documentation/VersionFile.md

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ VersionFile

Returns a new instance of VersionFile.



9
10
11
12
# File 'lib/version_file.rb', line 9

def initialize(path)
  @path = path
  parse
end

Instance Attribute Details

#frameworks_by_platformObject (readonly)

Returns the value of attribute frameworks_by_platform.



7
8
9
# File 'lib/version_file.rb', line 7

def frameworks_by_platform
  @frameworks_by_platform
end

#pathObject (readonly)

Returns the value of attribute path.



7
8
9
# File 'lib/version_file.rb', line 7

def path
  @path
end

#versionObject (readonly)

Returns the value of attribute version.



7
8
9
# File 'lib/version_file.rb', line 7

def version
  @version
end

Instance Method Details

#framework_namesObject

Unique array of framework names.



34
35
36
# File 'lib/version_file.rb', line 34

def framework_names
  @frameworks_by_platform.values.flatten.uniq.sort
end

#move_to_build_dirObject



43
44
45
46
47
48
# File 'lib/version_file.rb', line 43

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_frameworksObject

Total number of frameworks accross all platforms.



39
40
41
# File 'lib/version_file.rb', line 39

def number_of_frameworks
  @frameworks_by_platform.values.flatten.count
end

#platforms_by_frameworkObject

Returns a Hash, e.g. “‘

"CocoaLumberjack" => [:iOS, :watchOS],
"Lottie" => [:iOS],

“‘



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/version_file.rb', line 21

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

#removeObject



50
51
52
# File 'lib/version_file.rb', line 50

def remove
  FileUtils.rm(@path)
end

#same_content?(other_version_file) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
57
58
59
60
# File 'lib/version_file.rb', line 54

def same_content?(other_version_file)
  if other_version_file.nil?
    false
  else
    FileUtils.compare_file(@path, other_version_file.path)
  end
end