Sha256: e6de8723d40580eec79343e1561a851005caa7c8735250426b16b834a4b20ef8

Contents?: true

Size: 1.13 KB

Versions: 23

Compression:

Stored size: 1.13 KB

Contents

module Dataset
  class Load # :nodoc:
    attr_reader :datasets, :dataset_binding, :helper_methods
    
    def initialize(datasets, parent_binding)
      @datasets = datasets
      @dataset_binding = SessionBinding.new(parent_binding)
      @helper_methods = Module.new
    end
    
    def execute(loaded_datasets, dataset_resolver)
      (datasets - loaded_datasets).each do |dataset|
        instance = dataset.new
        instance.extend dataset_binding.record_methods
        instance.extend dataset_binding.model_finders
        used_datasets(dataset, dataset_resolver).each do |ds|
          next unless ds.helper_methods
          instance.extend ds.helper_methods
          helper_methods.module_eval do
            include ds.helper_methods
          end
        end
        instance.load
      end
    end
    
    def used_datasets(dataset, dataset_resolver, collector = [])
      dataset.used_datasets.each do |used|
        ds = dataset_resolver.resolve(used)
        used_datasets(ds, dataset_resolver, collector)
        collector << ds
      end if dataset.used_datasets
      collector << dataset
      collector.uniq
    end
  end
end

Version data entries

23 entries across 23 versions & 3 rubygems

Version Path
radiantcms-couchrest_model-0.1 vendor/plugins/dataset/lib/dataset/load.rb
radiant-0.9.1 vendor/plugins/dataset/lib/dataset/load.rb
radiant-0.9.0.rc2 vendor/plugins/dataset/lib/dataset/load.rb