Class: Spider::Model::Storage::Db::Reflector
- Defined in:
- lib/spiderfw/model/storage/db/reflector.rb
Instance Method Summary collapse
- #column_to_element_name(column_name) ⇒ Object
- #field_to_element(table_name, column_name, column_details, storage) ⇒ Object
- #reflect_table(storage, table_name, target) ⇒ Object
- #table_to_model_name(table_name) ⇒ Object
Instance Method Details
#column_to_element_name(column_name) ⇒ Object
22 23 24 |
# File 'lib/spiderfw/model/storage/db/reflector.rb', line 22 def column_to_element_name(column_name) name = Inflector.underscore(column_name) end |
#field_to_element(table_name, column_name, column_details, storage) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/spiderfw/model/storage/db/reflector.rb', line 26 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 |
#reflect_table(storage, table_name, target) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/spiderfw/model/storage/db/reflector.rb', line 5 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 |