Sha256: e4acb8f3fa20d2ec4031759612c15ed4740fccc222004475579057bc51d3838e

Contents?: true

Size: 1.31 KB

Versions: 5

Compression:

Stored size: 1.31 KB

Contents

require 'pathname'
module ActiveMocker
  # @api private
  class SchemaReader

    attr_reader :model_name,
                :schema_file,
                :file_reader,
                :tables,
                :clear_cache,
                :schema_version,
                :cache_file,
                :cache_tables,
                :migration_dir

    def initialize(options={})
      @file_reader   = options[:file_reader] ||= FileReader
      @schema_file   = options[:schema_file]

    end

    def search(model_name)
      @model_name = model_name
      load_table
      @tables
    end

    private

    def table_name
      model_name
    end

    def load_table
      eval_file
      raise "#{table_name} table not found." unless tables
    end

    def eval_file
      m = Module.new
      @tables = m.module_eval(read_file).tables
    end

    def read_file
      file_reader.read(schema_file)
    end

  end

  class SchemaVersion

    def self.migration_dir(dir)
      @migration_dir = dir || '/Users/zeisler/dev/active_mocker/spec/lib/active_mocker/performance/migration'
    end

    def self.get
      return @schema_version unless @schema_version.nil?
      r = Dir["#{@migration_dir}/*"].last
      p = Pathname.new(r)
      s = p.basename.to_s.match(/(\d*)_.*\.rb/).captures
      @schema_version = s.first
    end

  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
active_mocker-1.6.4 lib/active_mocker/schema_reader.rb
active_mocker-1.6.3 lib/active_mocker/schema_reader.rb
active_mocker-1.6.2 lib/active_mocker/schema_reader.rb
active_mocker-1.6.1 lib/active_mocker/schema_reader.rb
active_mocker-1.6 lib/active_mocker/schema_reader.rb