Class: Vendor::VendorFile::Library::Base
- Inherits:
-
Object
- Object
- Vendor::VendorFile::Library::Base
- Defined in:
- lib/vendor/vendor_file/library/base.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#require ⇒ Object
Returns the value of attribute require.
-
#targets ⇒ Object
Returns the value of attribute targets.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
- #build_settings ⇒ Object
- #cache_path ⇒ Object
- #dependencies ⇒ Object
- #description ⇒ Object
- #display_name ⇒ Object
- #download ⇒ Object
- #files ⇒ Object
- #frameworks ⇒ Object
-
#initialize(attributes = {}) ⇒ Base
constructor
A new instance of Base.
-
#install(project, options = {}) ⇒ Object
This method sucks.
- #version_matches_any?(other_versions) ⇒ Boolean
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
#name ⇒ Object
Returns the value of attribute name.
11 12 13 |
# File 'lib/vendor/vendor_file/library/base.rb', line 11 def name @name end |
#parent ⇒ Object
Returns the value of attribute parent.
9 10 11 |
# File 'lib/vendor/vendor_file/library/base.rb', line 9 def parent @parent end |
#require ⇒ Object
Returns the value of attribute require.
13 14 15 |
# File 'lib/vendor/vendor_file/library/base.rb', line 13 def require @require end |
#targets ⇒ Object
Returns the value of attribute targets.
12 13 14 |
# File 'lib/vendor/vendor_file/library/base.rb', line 12 def targets @targets end |
#version ⇒ Object
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_settings ⇒ Object
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_path ⇒ Object
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 |
#dependencies ⇒ Object
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 |
#description ⇒ Object
192 193 194 |
# File 'lib/vendor/vendor_file/library/base.rb', line 192 def description [ name, version ].compact.join(" ") end |
#display_name ⇒ Object
188 189 190 |
# File 'lib/vendor/vendor_file/library/base.rb', line 188 def display_name description end |
#download ⇒ Object
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 |
#files ⇒ Object
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 |
#frameworks ⇒ Object
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, = {}) # 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 || [:targets] install_targets = [ @targets, [: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
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 |