Class: Vendor::VendorFile::Library::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/vendor/vendor_file/library/base.rb

Direct Known Subclasses

Git, Local, Remote

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Base

Returns a new instance of Base.



16
17
18
19
20
# File 'lib/vendor/vendor_file/library/base.rb', line 16

def initialize(attributes = {})
  @source_tree = :group
  @targets = [ :all ]
  attributes.each { |k, v| self.send("#{k}=", v) }
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



11
12
13
# File 'lib/vendor/vendor_file/library/base.rb', line 11

def name
  @name
end

#parentObject

Returns the value of attribute parent.



9
10
11
# File 'lib/vendor/vendor_file/library/base.rb', line 9

def parent
  @parent
end

#requireObject

Returns the value of attribute require.



13
14
15
# File 'lib/vendor/vendor_file/library/base.rb', line 13

def require
  @require
end

#targetsObject

Returns the value of attribute targets.



12
13
14
# File 'lib/vendor/vendor_file/library/base.rb', line 12

def targets
  @targets
end

#versionObject

Returns the value of attribute version.



14
15
16
# File 'lib/vendor/vendor_file/library/base.rb', line 14

def version
  @version
end

Instance Method Details

#<=>(other) ⇒ Object



179
180
181
182
# File 'lib/vendor/vendor_file/library/base.rb', line 179

def <=>(other)
  v = other.respond_to?(:version) ? other.version : other
  Vendor::Version.create(version) <=> Vendor::Version.create(v)
end

#==(other) ⇒ Object



184
185
186
# File 'lib/vendor/vendor_file/library/base.rb', line 184

def ==(other)
  other.name == name && other.version == version
end

#build_settingsObject



107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/vendor/vendor_file/library/base.rb', line 107

def build_settings
  # If the cache doesn't exist, download it
  download unless cache_exists?

  # Find the build settings
  build_settings = if manifest
    manifest['build_settings']
  elsif vendor_spec
    vendor_spec.build_settings
  end

  build_settings || []
end

#cache_pathObject



30
31
32
# File 'lib/vendor/vendor_file/library/base.rb', line 30

def cache_path
  File.join(Vendor.library_path, self.class.name.split('::').last.downcase, name)
end

#dependenciesObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/vendor/vendor_file/library/base.rb', line 76

def dependencies
  # If the cache doesn't exist, download it
  download unless cache_exists?

  # Find the dependencies
  dependencies = if manifest
    manifest['dependencies']
  elsif vendor_spec
    vendor_spec.dependencies
  end

  # Create remote objects to represent the dependencies
  (dependencies || []).map do |d|
    Vendor::VendorFile::Library::Remote.new(:name => d[0], :version => d[1], :parent => self, :targets => @targets)
  end
end

#descriptionObject



192
193
194
# File 'lib/vendor/vendor_file/library/base.rb', line 192

def description
  [ name, version ].compact.join(" ")
end

#display_nameObject



188
189
190
# File 'lib/vendor/vendor_file/library/base.rb', line 188

def display_name
  description
end

#downloadObject



34
35
36
# File 'lib/vendor/vendor_file/library/base.rb', line 34

def download
  # Do nothing by default, leave that up to the implementation
end

#filesObject



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/vendor/vendor_file/library/base.rb', line 121

def files
  # If the cache doesn't exist, download it
  download unless cache_exists?

  # Calculate the files we need to add. There are 3 different types
  # of installation:
  # 1) Installation from a manifest (a built lib)
  # 2) Loading the .vendorspec and seeing what files needed to be added
  # 3) Try to be smart and try and find files to install
  install_files = if manifest
                    manifest['files'].map do |file|
                      File.join(cache_path, "data", file)
                    end
                  elsif vendor_spec
                    vendor_spec.files.map do |file|
                      File.join(cache_path, file)
                    end
                  else
                    location = [ cache_path, self.require, "**/*.*" ].compact
                    Dir[ File.join *location ]
                  end

  # Remove files that are within folders with a ".", such as ".bundle"
  # and ".frameworks"
  install_files.reject do |file|
    file.gsub(cache_path, "") =~ /\/?[^\/]+\.[^\/]+\//
  end
end

#frameworksObject



93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/vendor/vendor_file/library/base.rb', line 93

def frameworks
  # If the cache doesn't exist, download it
  download unless cache_exists?

  # Find the frameworks
  frameworks = if manifest
    manifest['frameworks']
  elsif vendor_spec
    vendor_spec.frameworks
  end

  frameworks || []
end

#install(project, options = {}) ⇒ Object

This method sucks. What we should be doing is passing a library to the Xcode project class to install. We shouldn’t be interacting with it like this. Really, VendorFile::Library should extend Xcode::Library or something. That was its a little more modular.



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
66
67
68
69
70
71
72
73
74
# File 'lib/vendor/vendor_file/library/base.rb', line 41

def install(project, options = {})
  # If the cache doesn't exist, download it
  download unless cache_exists?

  Vendor.ui.info %{Installing #{display_name}}

  # Combine the local targets, with those targets specified in the options. Also
  # for sanity reasons, flatten and uniqify them.
  if @targets || options[:targets]
    install_targets = [ @targets, options[:targets] ].compact.flatten.uniq
  end

  # The destination in the XCode project
  destination = "Vendor/#{name}"

  # Remove the group, and recreate
  project.remove_group destination

  # Install the files back into the project
  files.each do |file|
    project.add_file :targets => install_targets, :path => destination,
                     :file => file, :source_tree => @source_tree
  end

  # Add frameworks
  frameworks.each do |framework|
    project.add_framework framework, :targets => install_targets
  end

  # Add compiler flags
  build_settings.each do |build_setting|
    project.add_build_setting build_setting[0], build_setting[1], :targets => install_targets, :from => self
  end
end

#version_matches_any?(other_versions) ⇒ Boolean

Returns:

  • (Boolean)


160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/vendor/vendor_file/library/base.rb', line 160

def version_matches_any?(other_versions)
  # If we have an equality matcher, we need sort through
  # the versions, and try and find the best match
  wants = Vendor::Version.new(version)

  # Sort them from the latest versions first
  versions = other_versions.map{|v| Vendor::Version.create(v) }.sort.reverse

  # We don't want to include pre-releases if the wants version
  # isn't a pre-release itself. If we're after "2.5.alpha", then
  # we should be able to include that, however if we're asking for
  # "2.5", then pre-releases shouldn't be included.
  unless wants.prerelease?
    versions = versions.reject { |v| v.prerelease? }
  end

  versions.find { |has| wants == has }
end