lib/ronin/cache/overlay.rb in ronin-0.1.1 vs lib/ronin/cache/overlay.rb in ronin-0.1.2

- old
+ new

@@ -19,15 +19,15 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #++ # +require 'ronin/cache/maintainer' require 'ronin/cache/extension' require 'ronin/cache/exceptions/extension_not_found' require 'ronin/cache/overlay_cache' require 'ronin/cache/config' -require 'ronin/persistence' require 'rexml/document' require 'repertoire' module Ronin @@ -41,36 +41,45 @@ OBJECTS_DIR = 'objects' # Local path to the overlay attr_reader :path - # Source URI of the overlay source + # URI that the overlay was installed from attr_reader :uri # Name of the overlay attr_reader :name - # Authors of the overlay - attr_reader :authors - # License that the overlay contents is under attr_reader :license + # Source URI of the overlay + attr_reader :source + + # Source View URI of the overlay + attr_reader :source_view + + # Website URI for the overlay + attr_reader :website + + # Maintainers of the overlay + attr_reader :maintainers + # Description attr_reader :description # # Creates a new Overlay object with the specified _path_, _media_type_ # and _uri_. # - def initialize(path,media_type=:nil,uri=nil,&block) + def initialize(path,media_type=nil,uri=nil,&block) @path = File.expand_path(path) @uri = uri super(@path,Repertoire::Media.types[media_type]) - load_metadata(&block) + initialize_metadata(&block) end # # Load the Overlay Cache from the given _path_. If _path is not # given, it will default to <tt>Config::REPOSITORY_CACHE_PATH</tt>. @@ -249,25 +258,31 @@ # # Caches the objects contained within overlay. # def cache_objects - ObjectContext.cache_objects_in(objects_dir) + require 'ronin/models' + + return ObjectContext.cache_objects_in(objects_dir) end # # Mirror the objects contained within the overlay. # def mirror_objects - ObjectContext.mirror_objects_in(objects_dir) + require 'ronin/models' + + return ObjectContext.mirror_objects_in(objects_dir) end # # Delete all objects that existed within the overlay. # def expunge_objects - ObjectContext.expunge_objects_from(objects_dir) + require 'ronin/models' + + return ObjectContext.expunge_objects_from(objects_dir) end # # Adds the overlay to the overlay cache. If a _block is given, # it will be passed the newly created Overlay after it has been @@ -285,16 +300,15 @@ # # Updates the overlay and reloads it's metadata. If a _block_ # is given it will be called after the overlay has been updated. # def update(&block) - mirror_objects - if media_type Repertoire.update(:media => media_type, :path => @path, :uri => @uri) end + mirror_objects return load_metadata(&block) end # # Removes the overlay from the overlay cache. If a _block_ is @@ -389,25 +403,62 @@ # # Loads the overlay metadata from the METADATA_FILE within the # overlay +path+. If a _block_ is given, it will be passed the # overlay after the metadata has been loaded. # - def load_metadata(&block) + def initialize_metadata(&block) metadata_path = File.join(@path,METADATA_FILE) + # set to default values + @name = File.basename(@path) + @license = nil + + @source = @uri + @source_view = @source + @website = @source_view + + @maintainers = [] + @description = nil + if File.file?(metadata_path) - metadata = REXML::Document.new(open(metadata_path)) + doc = REXML::Document.new(open(metadata_path)) + overlay = doc.elements['/ronin-overlay'] - metadata.elements.each('/ronin-overlay') do |repo| - @name = repo.elements['name'].get_text.to_s.strip - @license = repo.elements['license'].get_text.to_s.strip - @description = repo.elements['description'].get_text.to_s.strip + overlay.each_element('name[.]:first') do |name| + @name = name.text.strip end - else - @name = File.basename(@path) - @authors = [] - @license = nil - @description = '' + + overlay.each_element('license[.]:first') do |license| + @license = license.text.strip + end + + overlay.each_element('source[.]:first') do |source| + @source = source.text.strip + end + + overlay.each_element('source-view[.]:first') do |source_view| + @source_view = source_view.text.strip + end + + overlay.each_element('website[.]:first') do |website| + @website = website.text.strip + end + + overlay.each_element('maintainers/maintainer') do |maintainer| + if (name = maintainer.text('name')) + name.strip! + end + + if (email = maintainer.text('email')) + email.strip! + end + + @maintainers << Maintainer.new(name,email) + end + + overlay.each_element('description[.]:first') do |description| + @description = description.text.strip + end end block.call(self) if block return self end