Class: DataType::Symbol

Inherits:
Base
  • Object
show all
Defined in:
lib/dsl/data_types/primitives.rb

Overview

Symbol (defaults, specified by user)

Instance Attribute Summary

Attributes inherited from Base

#aliases

Instance Method Summary collapse

Methods inherited from Base

#==, #column, #column_default_changed?, #dangerous_migration_from?, default_mock, #initialize, long_text_mock, migrant_data_type?, short_text_mock, #structure_changes_from

Constructor Details

This class inherits a constructor from DataType::Base

Instance Method Details

#column_defaultsObject



114
115
116
117
# File 'lib/dsl/data_types/primitives.rb', line 114

def column_defaults
  # Just construct whatever the user wants
  {:type => ((serialized?)? :text : @value) || :string }.merge(@options)
end

#mockObject



119
120
121
122
123
124
125
126
127
128
# File 'lib/dsl/data_types/primitives.rb', line 119

def mock
  case @value || :string
    when :text then self.class.long_text_mock
    when :string then self.class.short_text_mock
    when :integer then Fixnum.default_mock
    when :decimal, :float then Float.default_mock
    when :datetime, :date then Date.default_mock
    when :serialized, :serialize then (@example)? @example : Hash.default_mock
  end
end

#serialized?Boolean

Returns:

  • (Boolean)


130
131
132
# File 'lib/dsl/data_types/primitives.rb', line 130

def serialized?
  %W{serialized serialize}.include?(@value.to_s)
end

#serialized_class_nameObject



134
135
136
137
138
# File 'lib/dsl/data_types/primitives.rb', line 134

def serialized_class_name
  klass_name = (@example)? @example.class.to_s : "Hash"      
  
  klass_name.constantize
end