Module: RailsCom::ModelHelper
- Defined in:
- lib/rails_com/model_helper.rb
Instance Method Summary collapse
Instance Method Details
#column_attributes ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rails_com/model_helper.rb', line 17 def column_attributes columns.map do |column| [ column.name.to_sym, column.default, column.type, column.sql_type, column.null, column.default_function ] end end |
#print_table(with_column: false) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rails_com/model_helper.rb', line 31 def print_table(with_column: false) columns.each do |column| info = with_column ? '# t.column' : '# ' info << " :#{column.name.to_sym}, :#{column.type}" info << ", precision: #{column.precision}" if column.precision info << ", scale: #{column.scale}" if column.scale info << ", limit: #{column.limit}" if column.limit if column.default && column.type == :string info << ", default: '#{column.default}'" elsif column.default info << ", default: #{column.default}" end info << ", null: false" unless column.null info << ", comment: '#{column.comment} type: #{column.sql_type}'" if column.comment puts info end nil end |
#to_factory_girl ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/rails_com/model_helper.rb', line 3 def to_factory_girl require 'rails/generators' require 'generators/factory_girl/model/model_generator' args = [ self.name.underscore ] cols = columns.map { |col| "#{col.name}:#{col.type}" } generator = FactoryGirl::Generators::ModelGenerator.new(args + cols, destination_root: Rails.root) generator.invoke_all end |