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, platforms = PLATFORMS) ⇒ VersionFile

Returns a new instance of VersionFile.



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

def initialize(path, platforms = PLATFORMS)
  @path = path
  @platforms = platforms
  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

#jsonObject (readonly)

Returns the value of attribute json.



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

def json
  @json
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

#platformsObject (readonly)

Returns the value of attribute platforms.



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

def platforms
  @platforms
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.



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

def framework_names
  framework_names_by_platform.values.flatten.uniq.sort
end

#framework_names_by_platformObject



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

def framework_names_by_platform
  @frameworks_by_platform.map { |platform, framework| [platform, framework.map { |f| f.name }] }.to_h
end

#move_to_build_dirObject



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

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.



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

def number_of_frameworks
  framework_names_by_platform.values.flatten.count
end

#platforms_by_frameworkObject

Returns a Hash, e.g. “‘

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

“‘



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

def platforms_by_framework
  result = Hash.new { |h, k| h[k] = [] }
  for framework_name in framework_names
    framework_names_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



55
56
57
# File 'lib/version_file.rb', line 55

def remove
  FileUtils.rm(@path)
end

#same_content?(other_version_file) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
62
63
64
65
# File 'lib/version_file.rb', line 59

def same_content?(other_version_file)
  if other_version_file.nil?
    false
  else
    @json == other_version_file.json
  end
end