Sha256: 9393b9d3eccf6a96caa226f5e80fbe9bea4a0986b1162c994bb13c0b23297440

Contents?: true

Size: 1.32 KB

Versions: 5

Compression:

Stored size: 1.32 KB

Contents

# TODO: Figure out how to iterate each ORM framework AR, DM, MM and test each.
require 'active_record'
require 'active_support'
require 'extjs-mvc'
require 'extlib/inflection'

gem 'sqlite3-ruby'

class Test::App
  
  attr_reader :models
  
  def initialize(orm = :active_record)
    @orm = orm
    @config = YAML::load(IO.read("#{ROOT}/config/database.yml"))
    
    # Load ORM
    send("boot_#{orm.to_s}")
    
    load_models

    require 'db/schema'
    
  end
  
  ##
  # Reset a model's @extjs_fieldsets
  #
  def clean_all
    @models.map { |klass| clean klass }
  end
  
  
private
  
  def boot_active_record
    ActiveRecord::Base.establish_connection(@config['test'])
  end
  
  def boot_mongo_mapper
    
  end
  
  def boot_data_mapper
    
  end
  
  ##
  # Do a dir on /models and constantize each filename
  #
  def load_models
    @models = []
    # Load Models and Schema for corresponding orm
    re = /^.*\/(.*).rb$/
    Dir["#{ROOT}/models/#{@orm.to_s}/*"].each { |c| 
        require c 
        match = c.match(re)
        @models << Extlib::Inflection.constantize(Extlib::Inflection.camelize(match[1])) if match
    }
  end
  
  def clean klass
    klass.instance_variables.each do |var_name|
      if /\A@extjs_fieldsets__/ =~ var_name.to_s
        klass.instance_variable_set( var_name.to_sym, nil )
      end
    end
  end
  
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
extjs-mvc-0.3.10 test/app/config/application.rb
extjs-mvc-0.3.9 test/app/config/application.rb
extjs-mvc-0.3.8 test/app/config/application.rb
extjs-mvc-0.3.7 test/app/config/application.rb
extjs-mvc-0.3.6 test/app/config/application.rb