Class: SqlServerSchemaReflector::TableReflection
- Inherits:
-
Object
- Object
- SqlServerSchemaReflector::TableReflection
- Defined in:
- lib/sqlserver_schema_reflector/table_reflection.rb
Instance Method Summary collapse
- #columns ⇒ Object
- #constraints ⇒ Object
- #create_sql ⇒ Object
- #identity ⇒ Object
- #indexes ⇒ Object
-
#initialize(properties, options = {}) ⇒ TableReflection
constructor
A new instance of TableReflection.
- #meta ⇒ Object
Constructor Details
#initialize(properties, options = {}) ⇒ TableReflection
Returns a new instance of TableReflection.
2 3 4 5 6 7 8 9 |
# File 'lib/sqlserver_schema_reflector/table_reflection.rb', line 2 def initialize(properties, = {}) @properties = properties defaults = { :schema => [:owner] } defaults.merge! .merge! defaults end |
Instance Method Details
#columns ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/sqlserver_schema_reflector/table_reflection.rb', line 13 def columns if @columns.nil? @columns = [] column_hashes = @properties.find_hashes [:column_name, :type] column_hashes = [column_hashes] if column_hashes.class.name == 'Hash' column_hashes.each do |column| @columns.push(SqlServerSchemaReflector::ColumnReflection.new(column, identity)) end end @columns end |
#constraints ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/sqlserver_schema_reflector/table_reflection.rb', line 39 def constraints if @constraints.nil? @constraints = @properties.find_hashes [:constraint_name, :constraint_type] @constraints = [@constraints] if @constraints.class.name === 'Hash' end @constraints end |
#create_sql ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/sqlserver_schema_reflector/table_reflection.rb', line 46 def create_sql sql = "CREATE TABLE [#{[:schema]}].[#{[:name]}](" columns.each do |c| sql << "\n\t#{c.sql}," end sql << "\n)" end |
#identity ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/sqlserver_schema_reflector/table_reflection.rb', line 24 def identity if @identity.nil? @identity = @properties.find_hashes [:identity, :seed, :increment] @identity[:seed] = @identity[:seed].to_f.to_i @identity[:increment] = @identity[:increment].to_f.to_i end @identity end |
#indexes ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/sqlserver_schema_reflector/table_reflection.rb', line 32 def indexes if @indexes.nil? @indexes = @properties.find_hashes [:index_name, :index_description, :index_keys] @indexes = [@indexes] if @indexes.class.name === 'Hash' end @indexes end |
#meta ⇒ Object
10 11 12 |
# File 'lib/sqlserver_schema_reflector/table_reflection.rb', line 10 def @meta ||= @properties.find_hashes [:name, :owner, :type] end |