Class: SqlServerSchemaReflector::ColumnReflection

Inherits:
Object
  • Object
show all
Defined in:
lib/sqlserver_schema_reflector/column_reflection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(properties, identity = nil) ⇒ ColumnReflection

Returns a new instance of ColumnReflection.



3
4
5
6
7
8
# File 'lib/sqlserver_schema_reflector/column_reflection.rb', line 3

def initialize(properties, identity = nil)
  @properties = properties
  if identity[:identity] === properties[:column_name]
    @identity = identity unless identity.nil?
  end
end

Instance Attribute Details

#identityObject (readonly)

Returns the value of attribute identity.



2
3
4
# File 'lib/sqlserver_schema_reflector/column_reflection.rb', line 2

def identity
  @identity
end

Instance Method Details

#id_statementObject



23
24
25
# File 'lib/sqlserver_schema_reflector/column_reflection.rb', line 23

def id_statement    
  "IDENTITY(#{@identity[:seed]},#{@identity[:increment]})" unless @identity.nil?
end

#lengthObject



15
16
17
# File 'lib/sqlserver_schema_reflector/column_reflection.rb', line 15

def length
  "(#{@properties[:length]})" unless @properties[:length].nil? || type === 'int'
end

#nameObject



9
10
11
# File 'lib/sqlserver_schema_reflector/column_reflection.rb', line 9

def name
  @properties[:column_name]
end

#nullableObject



18
19
20
21
22
# File 'lib/sqlserver_schema_reflector/column_reflection.rb', line 18

def nullable
  _nullable = "NOT NULL"
  _nullable = "NULL" if @properties[:nullable] === 'yes'
  _nullable
end

#sqlObject



26
27
28
# File 'lib/sqlserver_schema_reflector/column_reflection.rb', line 26

def sql
  "[#{name}] [#{type}]#{length} #{id_statement} #{nullable}"
end

#typeObject



12
13
14
# File 'lib/sqlserver_schema_reflector/column_reflection.rb', line 12

def type
  @properties[:type]
end