Loads RText files into a FragmentedModel.

A glob pattern or file provider specifies the files which should be loaded. The load method can be called to load and to reload the model. Only changed files will be reloaded.

Optionally, the loader can use a fragment cache to speed up loading.

Public Class Methods

new(language, fragmented_model, options={}) click to toggle source

Create a default loader for language, loading into fragmented_model. It will find files either by evaluating the glob pattern given with :pattern (see Dir.glob) or by means of a file_provider. Options:

  a glob pattern or an array of glob patterns
  alternatively, a +:file_provider+ may be specified

  a proc which is called without any arguments and should return the files to load
  this is an alternative to providing +:pattern+

  a fragment cache to be used for loading

  if set to true, don't reload fragments which have parse errors 
  instead keep the existing fragment but attach the new problem list
# File lib/rtext/default_loader.rb, line 36
def initialize(language, fragmented_model, options={})
  @lang = language
  @model = fragmented_model
  @files_added = []
  @files_changed = []
  @files_removed = []
  @change_detector =
    :file_added => lambda {|f| @files_added << f }, 
    :file_removed => lambda {|f| @files_removed << f},
    :file_changed => lambda {|f| @files_changed << f})
  @cache = options[:cache]
  @fragment_by_file = {}
  pattern = options[:pattern]
  @file_provider = options[:file_provider] || proc { Dir.glob(pattern) }
  @dont_reload_with_errors = options[:dont_reload_with_errors]

Public Instance Methods

load(options={}) click to toggle source

Loads or reloads model fragments from files using the file patterns or file provider specified in the constructor. Options:

  a proc which is called before a file is actually loaded, receives the fragment to load
  into and a symbol indicating the kind of loading: :load, :load_cached, :load_update_cache
  optionally, the proc may take third argument which is the overall number of files
  default: no before load proc

  a proc which is called after a file has been loaded, receives the fragment loaded
  optionally, the proc may take second argument which is the overall number of files
  default: no after load proc

  a proc which is called when some progress is made 
  receives the current fragment being loaded, the actual work done as an integer and
  the overall work to be done as an integer
  default: no on progress proc
# File lib/rtext/default_loader.rb, line 73
def load(options={})
  @before_load_proc = options[:before_load]
  @after_load_proc = options[:after_load]
  files = 
  @num_files = files.size
  @files_added = []
  @files_changed = []
  @files_removed = []
  @progress_monitor =[:on_progress], @files_added + @files_changed)
  @files_added.each {|f| file_added(f)}
  @files_changed.each {|f| file_changed(f)}
  @files_removed.each {|f| file_removed(f)}, @model)
  @model.resolve(:fragment_provider => method(:fragment_provider),
    :use_target_type => @lang.per_type_identifier)


Generated with the Darkfish Rdoc Generator 2.