Sha256: fda2c4e8cc74572c70c65c3311f152b9223f195e485c9f3be8576c391ce0ec9b

Contents?: true

Size: 719 Bytes

Versions: 2

Compression:

Stored size: 719 Bytes

Contents

module Ryakuzu
  class CreateTableService
    attr_reader :table, :column, :type

    def initialize(table, column, type)
      @table  = table['name']
      @column = column
      @type   = type
    end

    def call
      invoke_migration
    end

    private

    def invoke_migration
      return if column.blank? || type.blank? || table.blank?
      res    = column.zip(type)
      hash   = Hash[*res.flatten]
      string = make_string(hash)
      text = "rails g model #{table.classify} #{string} && rake db:migrate"
      system text
    end

    def make_string(hash)
      str = ''
      hash.each do |key, value|
        str += key + ':' + value.downcase + ' ' if value
      end
      str
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ryakuzu-0.3.0 lib/ryakuzu/services/create_table_service.rb
ryakuzu-0.2.6 app/services/ryakuzu/create_table_service.rb