Sha256: 4247987e09318fe53d95973a2dc4c4f662aa4df077262b91837f58f66c547b0f

Contents?: true

Size: 1.65 KB

Versions: 23

Compression:

Stored size: 1.65 KB

Contents

module Dataset
  class Session # :nodoc:
    attr_accessor :dataset_resolver
    
    def initialize(database, dataset_resolver = Resolver.default)
      @database = database
      @dataset_resolver = dataset_resolver
      @datasets = Hash.new
      @load_stack = []
    end
    
    def add_dataset(test_class, dataset_identifier)
      dataset = dataset_resolver.resolve(dataset_identifier)
      if dataset.used_datasets
        dataset.used_datasets.each { |used_dataset| self.add_dataset(test_class, used_dataset) }
      end
      datasets_for(test_class) << dataset
    end
    
    def datasets_for(test_class)
      if test_class.superclass
        @datasets[test_class] ||= Collection.new(datasets_for(test_class.superclass) || [])
      end
    end
    
    def load_datasets_for(test_class)
      datasets = datasets_for(test_class)
      if last_load = @load_stack.last
        if last_load.datasets == datasets
          current_load = Reload.new(last_load)
        elsif last_load.datasets.subset?(datasets)
          @database.capture(last_load.datasets)
          current_load = Load.new(datasets, last_load.dataset_binding)
          current_load.execute(last_load.datasets, @dataset_resolver)
          @load_stack.push(current_load)
        else
          @load_stack.pop
          last_load = @load_stack.last
          @database.restore(last_load.datasets) if last_load
          current_load = load_datasets_for(test_class)
        end
      else
        @database.clear
        current_load = Load.new(datasets, @database)
        current_load.execute([], @dataset_resolver)
        @load_stack.push(current_load)
      end
      current_load
    end
  end
end

Version data entries

23 entries across 23 versions & 7 rubygems

Version Path
aiwilliams-dataset-1.2.0 lib/dataset/session.rb
aiwilliams-dataset-1.3.0 lib/dataset/session.rb
aiwilliams-dataset-1.3.1 lib/dataset/session.rb
karsthammer-dataset-1.2.0 lib/dataset/session.rb
codders-dataset-1.3.2.1 lib/dataset/session.rb
radiantcms-couchrest_model-0.2.4 vendor/plugins/dataset/lib/dataset/session.rb
radiantcms-couchrest_model-0.2.2 vendor/plugins/dataset/lib/dataset/session.rb
radiantcms-couchrest_model-0.2.1 vendor/plugins/dataset/lib/dataset/session.rb
radiantcms-couchrest_model-0.2 vendor/plugins/dataset/lib/dataset/session.rb
radiantcms-couchrest_model-0.1.9 vendor/plugins/dataset/lib/dataset/session.rb
radiantcms-couchrest_model-0.1.8 vendor/plugins/dataset/lib/dataset/session.rb
radiantcms-couchrest_model-0.1.7 vendor/plugins/dataset/lib/dataset/session.rb
radiantcms-couchrest_model-0.1.6 vendor/plugins/dataset/lib/dataset/session.rb
radiantcms-couchrest_model-0.1.5 vendor/plugins/dataset/lib/dataset/session.rb
radiant-0.7.2 vendor/plugins/dataset/lib/dataset/session.rb
be9-dataset-1.3.3 lib/dataset/session.rb
radiant-0.8.2 vendor/plugins/dataset/lib/dataset/session.rb
dataset-1.3.2 lib/dataset/session.rb
dataset-1.3.1 lib/dataset/session.rb
radiant-0.8.1 vendor/plugins/dataset/lib/dataset/session.rb