Sha256: 2c97c10e4df90b3c860563834e902cf4fdc4241707ec9e5449edbbf8214e0f40

Contents?: true

Size: 1.31 KB

Versions: 61

Compression:

Stored size: 1.31 KB

Contents

module Spider; module Model; module Storage; module Db
    
    class Reflector
       
       def reflect_table(storage, table_name, target)
           mod = Class.new(Spider::Model::BaseModel)
           model_name = table_to_model_name(table_name)
           target.const_set(model_name, mod)
           table = storage.describe_table(table_name)
           table[:columns].each do |column_name, column|
               name, type, attributes = field_to_element(table_name, column_name, column, storage)
               mod.element(name, type, attributes)
           end
           mod.attributes[:db_table]  = table_name
           return mod
       end
       
       def table_to_model_name(table_name)
           model_name = Spider::Inflector.camelize(table_name)
       end
       
       def column_to_element_name(column_name)
           name = Inflector.underscore(column_name)
       end
       
       def field_to_element(table_name, column_name, column_details, storage)
           type, attributes = storage.reflect_column(table_name, column_name, column_details)
           attributes[:primary_key] = true if (column_details[:primary_key])
           attributes[:db_column_name] = column_name
           return column_to_element_name(column_name), type, attributes
       end
        
    end
    
    
end; end; end; end

Version data entries

61 entries across 61 versions & 1 rubygems

Version Path
spiderfw-1.0.1 lib/spiderfw/model/storage/db/reflector.rb
spiderfw-1.0.0 lib/spiderfw/model/storage/db/reflector.rb
spiderfw-0.6.39 lib/spiderfw/model/storage/db/reflector.rb
spiderfw-0.6.38 lib/spiderfw/model/storage/db/reflector.rb
spiderfw-0.6.37 lib/spiderfw/model/storage/db/reflector.rb
spiderfw-0.6.35 lib/spiderfw/model/storage/db/reflector.rb
spiderfw-0.6.34 lib/spiderfw/model/storage/db/reflector.rb
spiderfw-0.6.33 lib/spiderfw/model/storage/db/reflector.rb
spiderfw-0.6.32 lib/spiderfw/model/storage/db/reflector.rb
spiderfw-0.6.31 lib/spiderfw/model/storage/db/reflector.rb
spiderfw-0.6.30 lib/spiderfw/model/storage/db/reflector.rb
spiderfw-0.6.29 lib/spiderfw/model/storage/db/reflector.rb
spiderfw-0.6.28 lib/spiderfw/model/storage/db/reflector.rb
spiderfw-0.6.27 lib/spiderfw/model/storage/db/reflector.rb
spiderfw-0.6.26 lib/spiderfw/model/storage/db/reflector.rb
spiderfw-0.6.26.pre1 lib/spiderfw/model/storage/db/reflector.rb
spiderfw-0.6.25 lib/spiderfw/model/storage/db/reflector.rb
spiderfw-0.6.24 lib/spiderfw/model/storage/db/reflector.rb
spiderfw-0.6.23 lib/spiderfw/model/storage/db/reflector.rb
spiderfw-0.6.22 lib/spiderfw/model/storage/db/reflector.rb