Class: Drupid::Component
- Inherits:
-
Object
- Object
- Drupid::Component
- Includes:
- Utils
- Defined in:
- lib/drupid/component.rb
Instance Attribute Summary collapse
-
#download_specs ⇒ Object
Returns the value of attribute download_specs.
-
#download_type ⇒ Object
Returns the value of attribute download_type.
-
#download_url ⇒ Object
Returns the value of attribute download_url.
-
#ignore_paths ⇒ Object
readonly
Returns the value of attribute ignore_paths.
-
#local_path ⇒ Object
Returns the value of attribute local_path.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#overwrite ⇒ Object
Returns the value of attribute overwrite.
Instance Method Summary collapse
- #add_download_spec(spec, ref) ⇒ Object
- #add_patch(url, descr, md5 = nil) ⇒ Object
-
#cached_location ⇒ Object
Full path to the location where a cached copy of this component is located.
-
#clear_patches ⇒ Object
Removes all the patches from this component.
-
#clone ⇒ Object
Performs a deep copy of this object.
-
#directory_name ⇒ Object
Returns the directory name for this component.
-
#directory_name=(d) ⇒ Object
Sets the directory name for this component.
-
#each_patch ⇒ Object
Iterates over each patch associated to this component, yielding a Drupid::Patch object.
-
#exist? ⇒ Boolean
Returns true if this project is associated to a local copy on disk; returns false otherwise.
- #extended_name ⇒ Object
-
#fetch ⇒ Object
Downloads to local cache.
-
#file_level_compare_with(tgt, additional_rsync_args = []) ⇒ Object
Performs a file-by-file comparison of this component with another.
-
#get_patch(descr) ⇒ Object
Returns the first patch with the given description, or nil if no such patch exists.
-
#has_patches? ⇒ Boolean
Returns true if patches are associated to this component, returns false otherwise.
-
#ignore_path(relative_path) ⇒ Object
Ignores the given path relative to this component’s path.
-
#initialize(name) ⇒ Component
constructor
A new instance of Component.
-
#patch ⇒ Object
Applies the patches associated to this component.
-
#patched? ⇒ Boolean
Returns true if this component has been patched; returns false otherwise.
-
#patched_location ⇒ Object
Full path to the directory where a patched copy of this component is located.
-
#subdir ⇒ Object
Returns a path to a subdirectory where this component should be installed.
-
#subdir=(d) ⇒ Object
Sets the path to a subdirectory where this component should be installed, relative to the default installation path.
-
#to_s ⇒ Object
A synonym for #extended_name.
Methods included from Utils
#blah, #bzr, #compare_paths, #curl, #cvs, #debug, #dont_debug, #git, #hg, #ignore_interrupts, #interactive_shell, #odie, #ofail, #ohai, #owarn, #runBabyRun, #svn, #tempdir, #uncompress, #which, #writeFile
Constructor Details
#initialize(name) ⇒ Component
Returns a new instance of Component.
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/drupid/component.rb', line 51 def initialize name @name = name @download_url = nil @download_type = nil @download_specs = Hash.new @overwrite = false @subdir = nil @directory_name = nil @local_path = nil @ignore_paths = Array.new @patches = Array.new end |
Instance Attribute Details
#download_specs ⇒ Object
Returns the value of attribute download_specs.
46 47 48 |
# File 'lib/drupid/component.rb', line 46 def download_specs @download_specs end |
#download_type ⇒ Object
Returns the value of attribute download_type.
45 46 47 |
# File 'lib/drupid/component.rb', line 45 def download_type @download_type end |
#download_url ⇒ Object
Returns the value of attribute download_url.
44 45 46 |
# File 'lib/drupid/component.rb', line 44 def download_url @download_url end |
#ignore_paths ⇒ Object (readonly)
Returns the value of attribute ignore_paths.
49 50 51 |
# File 'lib/drupid/component.rb', line 49 def ignore_paths @ignore_paths end |
#local_path ⇒ Object
Returns the value of attribute local_path.
48 49 50 |
# File 'lib/drupid/component.rb', line 48 def local_path @local_path end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
43 44 45 |
# File 'lib/drupid/component.rb', line 43 def name @name end |
#overwrite ⇒ Object
Returns the value of attribute overwrite.
47 48 49 |
# File 'lib/drupid/component.rb', line 47 def overwrite @overwrite end |
Instance Method Details
#add_download_spec(spec, ref) ⇒ Object
113 114 115 |
# File 'lib/drupid/component.rb', line 113 def add_download_spec(spec, ref) @download_specs.merge!({spec => ref}) end |
#add_patch(url, descr, md5 = nil) ⇒ Object
182 183 184 |
# File 'lib/drupid/component.rb', line 182 def add_patch(url, descr, md5 = nil) @patches << Patch.new(url, descr, md5) end |
#cached_location ⇒ Object
Full path to the location where a cached copy of this component is located.
195 196 197 198 |
# File 'lib/drupid/component.rb', line 195 def cached_location dlt = (download_type) ? download_type : 'default' Drupid.cache_path + self.class.to_s.split(/::/).last + extended_name + dlt + name end |
#clear_patches ⇒ Object
Removes all the patches from this component.
158 159 160 |
# File 'lib/drupid/component.rb', line 158 def clear_patches @patches.clear end |
#clone ⇒ Object
Performs a deep copy of this object.
65 66 67 |
# File 'lib/drupid/component.rb', line 65 def clone Marshal.load(Marshal.dump(self)) end |
#directory_name ⇒ Object
Returns the directory name for this component.
96 97 98 99 100 |
# File 'lib/drupid/component.rb', line 96 def directory_name return @directory_name.to_s if @directory_name return local_path.basename.to_s if exist? return name end |
#directory_name=(d) ⇒ Object
Sets the directory name for this component.
103 104 105 |
# File 'lib/drupid/component.rb', line 103 def directory_name=(d) @directory_name = d end |
#each_patch ⇒ Object
Iterates over each patch associated to this component, yielding a Drupid::Patch object.
170 171 172 173 174 |
# File 'lib/drupid/component.rb', line 170 def each_patch @patches.each do |p| yield p end end |
#exist? ⇒ Boolean
Returns true if this project is associated to a local copy on disk; returns false otherwise.
109 110 111 |
# File 'lib/drupid/component.rb', line 109 def exist? @local_path and @local_path.exist? end |
#extended_name ⇒ Object
69 70 71 |
# File 'lib/drupid/component.rb', line 69 def extended_name @name end |
#fetch ⇒ Object
Downloads to local cache.
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/drupid/component.rb', line 118 def fetch if cached_location.exist? @local_path = cached_location debug "#{extended_name} is cached" else raise "No download URL specified for #{extended_name}" if download_url.nil? blah "Fetching #{extended_name}" downloader = Drupid.makeDownloader self.download_url.to_s, self.cached_location.dirname.to_s, self.cached_location.basename.to_s, self.download_specs downloader.fetch downloader.stage @local_path = downloader.staged_path end end |
#file_level_compare_with(tgt, additional_rsync_args = []) ⇒ Object
Performs a file-by-file comparison of this component with another. Returns a list of files that are different between the two copies. If the directories of the two projects look the same, returns an empty array. Local copies must exist for both projects, otherwise this method raises an error.
If one of the projects has a makefile, the content of the following directories is ignored: libraries, modules, themes. Version control directories (.git) are always ignored.
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/drupid/component.rb', line 220 def file_level_compare_with tgt, additional_rsync_args = [] raise "#{extended_name} does not exist at #{local_path}" unless exist? raise "#{tgt.extended_name} does not exist at #{tgt.local_path}" unless tgt.exist? args = Array.new default_exclusions = [ '.DS_Store', '.git/', '.bzr/', '.hg/', '.svn/' ] default_exclusions.each { |e| args << "--exclude=#{e}" } ignore_paths.each { |p| args << "--exclude=#{p}" } tgt.ignore_paths.each { |p| args << "--exclude=#{p}" } args += additional_rsync_args compare_paths local_path, tgt.local_path, args end |
#get_patch(descr) ⇒ Object
Returns the first patch with the given description, or nil if no such patch exists.
188 189 190 191 192 |
# File 'lib/drupid/component.rb', line 188 def get_patch descr @patches.each do |p| return p if descr == p.descr end end |
#has_patches? ⇒ Boolean
Returns true if patches are associated to this component, returns false otherwise.
178 179 180 |
# File 'lib/drupid/component.rb', line 178 def has_patches? !@patches.empty? end |
#ignore_path(relative_path) ⇒ Object
Ignores the given path relative to this component’s path. This is useful, for example, when an external library is installed inside a module’s folder (rather than in the libraries folder).
208 209 210 |
# File 'lib/drupid/component.rb', line 208 def ignore_path(relative_path) @ignore_paths << Pathname.new(relative_path) end |
#patch ⇒ Object
Applies the patches associated to this component. Raises an exception if a patch cannot be applied.
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/drupid/component.rb', line 137 def patch fetch unless exist? return unless has_patches? dont_debug { patched_location.rmtree if patched_location.exist? } # Make sure that no previous patched copy exists dont_debug { @local_path.ditto patched_location } @local_path = patched_location # Download patches patched_location.dirname.cd do each_patch do |p| p.fetch end end # Apply patches patched_location.cd do each_patch do |p| p.apply end end end |
#patched? ⇒ Boolean
Returns true if this component has been patched; returns false otherwise.
164 165 166 |
# File 'lib/drupid/component.rb', line 164 def patched? @local_path == patched_location end |
#patched_location ⇒ Object
Full path to the directory where a patched copy of this component is located.
201 202 203 |
# File 'lib/drupid/component.rb', line 201 def patched_location cached_location.dirname + '__patches' + name end |
#subdir ⇒ Object
Returns a path to a subdirectory where this component should be installed. The path is meant to be relative to the ‘default’ installation path (e.g., ‘sites/all/modules’ for modules, ‘sites/all/themes’ for themes, ‘profiles’ for profiles, etc…). For example, if a module ‘foobar’ must be installed under ‘sites/all/modules’ and this property is set, say, to ‘contrib’, then the module will be installed at ‘sites/all/modules/contrib/foobar’.
85 86 87 |
# File 'lib/drupid/component.rb', line 85 def subdir (@subdir) ? Pathname.new(@subdir) : Pathname.new('.') end |
#subdir=(d) ⇒ Object
Sets the path to a subdirectory where this component should be installed, relative to the default installation path.
91 92 93 |
# File 'lib/drupid/component.rb', line 91 def subdir=(d) @subdir = d end |
#to_s ⇒ Object
A synonym for #extended_name.
74 75 76 |
# File 'lib/drupid/component.rb', line 74 def to_s extended_name end |