Class Boson::RepoIndex

  1. lib/boson/repo_index.rb
Parent: Object

This class provides an index for commands and libraries of a given a Repo. When this index updates, it detects library files whose md5 hash have changed and reindexes them. The index is stored with Marshal at config/index.marshal (relative to a Repo’s root directory). Since the index is marshaled, putting lambdas/procs in it will break it.If an index gets corrupted, simply delete it and next time Boson needs it, the index will be recreated.

Methods

public class

  1. new

public instance

  1. read
  2. update
  3. write

Attributes

commands [R]
libraries [R]
repo [R]

Public class methods

new (repo)
[show source]
# File lib/boson/repo_index.rb, line 11
    def initialize(repo)
      @repo = repo
    end

Public instance methods

read ()

Reads and initializes index.

[show source]
# File lib/boson/repo_index.rb, line 35
    def read
      return if @read
      @libraries, @commands, @lib_hashes = exists? ?
        File.open( marshal_file, 'rb' ){|f| Marshal.load( f.read ) } : [[], [], {}]
      delete_stale_libraries_and_commands
      set_command_namespaces
      @read = true
    end
update (options={})

Updates the index.

[show source]
# File lib/boson/repo_index.rb, line 16
    def update(options={})
      libraries_to_update = !exists? ? repo.all_libraries : options[:libraries] || changed_libraries
      read_and_transfer(libraries_to_update)
      if options[:verbose]
        puts !exists? ? "Generating index for all #{libraries_to_update.size} libraries. Patience ... is a bitch" :
          (libraries_to_update.empty? ? "No libraries indexed" :
          "Indexing the following libraries: #{libraries_to_update.join(', ')}")
      end
      Manager.failed_libraries = []
      unless libraries_to_update.empty?
        Manager.load(libraries_to_update, options.merge(:index=>true))
        unless Manager.failed_libraries.empty?
          $stderr.puts("Error: These libraries failed to load while indexing: #{Manager.failed_libraries.join(', ')}")
        end
      end
      write(Manager.failed_libraries)
    end
write (failed_libraries=[])

Writes/saves current index to config/index.marshal.

[show source]
# File lib/boson/repo_index.rb, line 45
    def write(failed_libraries=[])
      latest = latest_hashes
      failed_libraries.each {|e| latest.delete(e) }
      save_marshal_index Marshal.dump([Boson.libraries, Boson.commands, latest])
    end