Class: VersionFile
- Inherits:
-
Object
- Object
- VersionFile
- 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
-
#frameworks_by_platform ⇒ Object
readonly
Returns the value of attribute frameworks_by_platform.
-
#json ⇒ Object
readonly
Returns the value of attribute json.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#platforms ⇒ Object
readonly
Returns the value of attribute platforms.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
-
#framework_names ⇒ Object
Unique array of framework names.
- #framework_names_by_platform ⇒ Object
-
#initialize(path, platforms = PLATFORMS) ⇒ VersionFile
constructor
A new instance of VersionFile.
- #move_to_build_dir ⇒ Object
-
#number_of_frameworks ⇒ Object
Total number of frameworks accross all platforms.
-
#platforms_by_framework ⇒ Object
Returns a Hash, e.g.
- #remove ⇒ Object
- #same_content?(other_version_file) ⇒ Boolean
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_platform ⇒ Object (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 |
#json ⇒ Object (readonly)
Returns the value of attribute json.
7 8 9 |
# File 'lib/version_file.rb', line 7 def json @json end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/version_file.rb', line 7 def path @path end |
#platforms ⇒ Object (readonly)
Returns the value of attribute platforms.
7 8 9 |
# File 'lib/version_file.rb', line 7 def platforms @platforms end |
#version ⇒ Object (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_names ⇒ Object
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_platform ⇒ Object
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_dir ⇒ Object
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_frameworks ⇒ Object
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_framework ⇒ Object
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 |
#remove ⇒ Object
55 56 57 |
# File 'lib/version_file.rb', line 55 def remove FileUtils.rm(@path) end |
#same_content?(other_version_file) ⇒ 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 |