Sha256: ce454d5d556ca2e0b54b0b3e0437e825fcb24c4438ad2c216ca990ea4d9b2400

Contents?: true

Size: 1.3 KB

Versions: 23

Compression:

Stored size: 1.3 KB

Contents

require 'pathname'
module ActiveMocker
  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

23 entries across 23 versions & 1 rubygems

Version Path
active_mocker-1.5.2 lib/active_mocker/schema_reader.rb
active_mocker-1.5.1 lib/active_mocker/schema_reader.rb
active_mocker-1.5 lib/active_mocker/schema_reader.rb
active_mocker-1.4.2 lib/active_mocker/schema_reader.rb
active_mocker-1.4.1 lib/active_mocker/schema_reader.rb
active_mocker-1.3.2 lib/active_mocker/schema_reader.rb
active_mocker-1.3.1 lib/active_mocker/schema_reader.rb
active_mocker-1.3 lib/active_mocker/schema_reader.rb
active_mocker-1.2.4 lib/active_mocker/schema_reader.rb
active_mocker-1.2.3 lib/active_mocker/schema_reader.rb
active_mocker-1.2 lib/active_mocker/schema_reader.rb
active_mocker-1.2.pre.11 lib/active_mocker/schema_reader.rb
active_mocker-1.2.pre.10 lib/active_mocker/schema_reader.rb
active_mocker-1.2.pre.9 lib/active_mocker/schema_reader.rb
active_mocker-1.2.pre.8 lib/active_mocker/schema_reader.rb
active_mocker-1.2.pre.7 lib/active_mocker/schema_reader.rb
active_mocker-1.2.pre.6 lib/active_mocker/schema_reader.rb
active_mocker-1.2.pre.5 lib/active_mocker/schema_reader.rb
active_mocker-1.2.pre.4 lib/active_mocker/schema_reader.rb
active_mocker-1.2.pre.3 lib/active_mocker/schema_reader.rb