Sha256: 4f0c60b8b079c3a86da6e62ca6be11e1019a3ee7fa3f2149022a61967993ebf9

Contents?: true

Size: 823 Bytes

Versions: 11

Compression:

Stored size: 823 Bytes

Contents

module ActiveMocker

  class SchemaReader

    attr_reader :model_name, :schema_file, :file_reader, :table

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

    def search(model_name)
      @model_name = model_name
      @table = search_schema_file
    end

    private

    def table_name
      model_name
    end

    def not_found
      raise "#{table_name} table not found." if @schema_result.nil?
    end

    def search_schema_file
      ActiveMocker::ActiveRecord::Schema.search(table_name)
      @schema_result = eval_file
      not_found
      @schema_result
    end

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

    def read_file
      file_reader.read(schema_file)
    end

  end

end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
active_mocker-1.1.6 lib/active_mocker/schema_reader.rb
active_mocker-1.1.5 lib/active_mocker/schema_reader.rb
active_mocker-1.1.4 lib/active_mocker/schema_reader.rb
active_mocker-1.1.3 lib/active_mocker/schema_reader.rb
active_mocker-1.1.2 lib/active_mocker/schema_reader.rb
active_mocker-1.1.1 lib/active_mocker/schema_reader.rb
active_mocker-1.1.0 lib/active_mocker/schema_reader.rb
active_mocker-1.0.1 lib/active_mocker/schema_reader.rb
active_mocker-1.0.0 lib/active_mocker/schema_reader.rb
active_mocker-0.4.0 lib/active_mocker/schema_reader.rb
active_mocker-0.3.1 lib/active_mocker/schema_reader.rb