Module: RailsTypeHelpers
- Included in:
- RailsTableHelpers
- Defined in:
- lib/metarecord/generators/rails/migrations/type_helpers.rb
Instance Method Summary collapse
- #get_record_type(type) ⇒ Object
- #is_integer_type?(type) ⇒ Boolean
- #on_unsupported_type(model_name, column_name, type_name) ⇒ Object
- #rails_type_name(type) ⇒ Object
- #type_options_string(type) ⇒ Object
Instance Method Details
#get_record_type(type) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/metarecord/generators/rails/migrations/type_helpers.rb', line 2 def get_record_type type case type when "Crails::Odb::id_type" then :bigint when "char" then :tinyint when "unsigned char" then :smallint when "short" then :smallint when "unsigned short" then :mediumint when "int" then :integer when "unsigned int" then :integer when "long" then :bigint when "long long" then :bigint when "unsigned long" then :bigint when "unsigned long long" then :bigint when "double" then :float when "long double" then :float when "float" then :float when "bool" then :boolean when "std::string" then :string when "std::time_t" then :timestamp else nil end end |
#is_integer_type?(type) ⇒ Boolean
29 30 31 |
# File 'lib/metarecord/generators/rails/migrations/type_helpers.rb', line 29 def is_integer_type? type [:tinyint, :smallint, :mediumint, :bigint, :integer].include? type end |
#on_unsupported_type(model_name, column_name, type_name) ⇒ Object
25 26 27 |
# File 'lib/metarecord/generators/rails/migrations/type_helpers.rb', line 25 def on_unsupported_type model_name, column_name, type_name puts "[metarecord][rails-migration] unsupported type #{type_name} for column `#{column_name}` in table `#{model_name}`" end |
#rails_type_name(type) ⇒ Object
33 34 35 |
# File 'lib/metarecord/generators/rails/migrations/type_helpers.rb', line 33 def rails_type_name type if is_integer_type? type then "integer" else type.to_s end end |
#type_options_string(type) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/metarecord/generators/rails/migrations/type_helpers.rb', line 37 def type if is_integer_type? type table = { tinyint: 1, smallint: 2, mediumint: 3, integer: 4, bigint: 8 } ", limit: #{table[type]}" else "" end end |