class Drupid::Component

Attributes

download_specs[RW]
download_type[RW]
download_url[RW]
ignore_paths[R]
local_path[RW]
name[R]
overwrite[RW]

Public Class Methods

new(name) click to toggle source
   # File lib/drupid/component.rb
50 def initialize name
51   @name           = name
52   @download_url   = nil
53   @download_type  = nil
54   @download_specs = Hash.new
55   @overwrite      = false
56   @subdir         = nil
57   @directory_name = nil
58   @local_path     = nil
59   @ignore_paths   = Array.new
60   @patches        = Array.new
61 end

Public Instance Methods

add_download_spec(spec, ref) click to toggle source
    # File lib/drupid/component.rb
112 def add_download_spec(spec, ref)
113   @download_specs.merge!({spec => ref})
114 end
add_patch(url, descr, md5 = nil) click to toggle source
    # File lib/drupid/component.rb
181 def add_patch(url, descr, md5 = nil)
182   @patches << Patch.new(url, descr, md5)
183 end
cached_location() click to toggle source

Full path to the location where a cached copy of this component is located.

    # File lib/drupid/component.rb
194 def cached_location
195   dlt = (download_type) ? download_type : 'default'
196   Drupid.cache_path + self.class.to_s.split(/::/).last + extended_name + dlt + name
197 end
clear_patches() click to toggle source

Removes all the patches from this component.

    # File lib/drupid/component.rb
157 def clear_patches
158   @patches.clear
159 end
clone() click to toggle source

Performs a deep copy of this object.

   # File lib/drupid/component.rb
64 def clone
65   Marshal.load(Marshal.dump(self))
66 end
directory_name() click to toggle source

Returns the directory name for this component.

   # File lib/drupid/component.rb
95 def directory_name
96   return @directory_name.to_s if @directory_name
97   return local_path.basename.to_s if exist?
98   return name
99 end
directory_name=(d) click to toggle source

Sets the directory name for this component.

    # File lib/drupid/component.rb
102 def directory_name=(d)
103   @directory_name = d
104 end
each_patch() { |p| ... } click to toggle source

Iterates over each patch associated to this component, yielding a Drupid::Patch object.

    # File lib/drupid/component.rb
169 def each_patch
170   @patches.each do |p|
171     yield p
172   end
173 end
exist?() click to toggle source

Returns true if this project is associated to a local copy on disk; returns false otherwise.

    # File lib/drupid/component.rb
108 def exist?
109   @local_path and @local_path.exist?
110 end
extended_name() click to toggle source
   # File lib/drupid/component.rb
68 def extended_name
69   @name
70 end
fetch() click to toggle source

Downloads to local cache.

    # File lib/drupid/component.rb
117 def fetch
118   if cached_location.exist?
119     @local_path = cached_location
120     debug "#{extended_name} is cached"
121   else
122     raise "No download URL specified for #{extended_name}" if download_url.nil?
123     blah "Fetching #{extended_name}"
124     downloader = Drupid.makeDownloader self.download_url.to_s,
125                                        self.cached_location.dirname.to_s,
126                                        self.cached_location.basename.to_s,
127                                        self.download_specs
128     downloader.fetch
129     downloader.stage
130     @local_path = downloader.staged_path
131   end
132 end
file_level_compare_with(tgt, additional_rsync_args = []) click to toggle source

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.

    # File lib/drupid/component.rb
219 def file_level_compare_with tgt, additional_rsync_args = []
220   raise "#{extended_name} does not exist at #{local_path}" unless exist?
221   raise "#{tgt.extended_name} does not exist at #{tgt.local_path}" unless tgt.exist?
222   args = Array.new
223   default_exclusions = [
224     '.DS_Store',
225     '.git/',
226     '.bzr/',
227     '.hg/',
228     '.svn/'
229   ]
230   default_exclusions.each { |e| args << "--exclude=#{e}" }
231   ignore_paths.each       { |p| args << "--exclude=#{p}" }
232   tgt.ignore_paths.each   { |p| args << "--exclude=#{p}" }
233   args += additional_rsync_args
234   compare_paths local_path, tgt.local_path, args
235 end
get_patch(descr) click to toggle source

Returns the first patch with the given description, or nil if no such patch exists.

    # File lib/drupid/component.rb
187 def get_patch descr
188   @patches.each do |p|
189     return p if descr == p.descr
190   end
191 end
has_patches?() click to toggle source

Returns true if patches are associated to this component, returns false otherwise.

    # File lib/drupid/component.rb
177 def has_patches?
178   !@patches.empty?
179 end
ignore_path(relative_path) click to toggle source

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).

    # File lib/drupid/component.rb
207 def ignore_path(relative_path)
208   @ignore_paths << Pathname.new(relative_path)
209 end
patch() click to toggle source

Applies the patches associated to this component. Raises an exception if a patch cannot be applied.

    # File lib/drupid/component.rb
136 def patch
137   fetch unless exist?
138   return unless has_patches?
139   dont_debug { patched_location.rmtree if patched_location.exist? } # Make sure that no previous patched copy exists
140   dont_debug { @local_path.ditto patched_location }
141   @local_path = patched_location
142   # Download patches
143   patched_location.dirname.cd do
144     each_patch do |p|
145       p.fetch
146     end
147   end
148   # Apply patches
149   patched_location.cd do
150     each_patch do |p|
151       p.apply
152     end
153   end
154 end
patched?() click to toggle source

Returns true if this component has been patched; returns false otherwise.

    # File lib/drupid/component.rb
163 def patched?
164   @local_path == patched_location
165 end
patched_location() click to toggle source

Full path to the directory where a patched copy of this component is located.

    # File lib/drupid/component.rb
200 def patched_location
201   cached_location.dirname + '__patches' + name
202 end
subdir() click to toggle source

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’.

   # File lib/drupid/component.rb
84 def subdir
85   (@subdir) ? Pathname.new(@subdir) : Pathname.new('.')
86 end
subdir=(d) click to toggle source

Sets the path to a subdirectory where this component should be installed, relative to the default installation path.

   # File lib/drupid/component.rb
90 def subdir=(d)
91   @subdir = d
92 end
to_s() click to toggle source

A synonym for extended_name.

   # File lib/drupid/component.rb
73 def to_s
74   extended_name
75 end