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



135
136
137
138
# File 'lib/vendor/vendor_file/library/base.rb', line 135

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

#==(other) ⇒ Object



140
141
142
# File 'lib/vendor/vendor_file/library/base.rb', line 140

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

#build_settingsObject



69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/vendor/vendor_file/library/base.rb', line 69

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



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/vendor/vendor_file/library/base.rb', line 38

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



148
149
150
# File 'lib/vendor/vendor_file/library/base.rb', line 148

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

#display_nameObject



144
145
146
# File 'lib/vendor/vendor_file/library/base.rb', line 144

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



83
84
85
# File 'lib/vendor/vendor_file/library/base.rb', line 83

def files
  install_files_for_files_in 'files'
end

#frameworksObject



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/vendor/vendor_file/library/base.rb', line 55

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

#per_file_flagObject



101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/vendor/vendor_file/library/base.rb', line 101

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

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

  per_file_flag
end

#resourcesObject



87
88
89
# File 'lib/vendor/vendor_file/library/base.rb', line 87

def resources
  install_files_for_files_in 'resources'
end

#version_matches_any?(other_versions) ⇒ Boolean

Returns:

  • (Boolean)


116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/vendor/vendor_file/library/base.rb', line 116

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