Sha256: 9a4b2421936dbafecb21732a776fea6c2acd1edfc262e2e5e008e3e91e008501

Contents?: true

Size: 1.41 KB

Versions: 25

Compression:

Stored size: 1.41 KB

Contents

class Card
  class FileCardCreator
    class AbstractFileCard
      # Module that provides #create_migration_file method for classes that
      # inherit from AbstractFileCard.
      # It uses the decko generator to create the migration.
      module MigrationFile
        def create_migration_file
          puts "creating migration file...".yellow
          migration_out = `#{migrate_command}`
          return if migration_out.include?("conflict")
          migration_file_name = migration_out[/db.*/]
          write_at migration_file_name, 5, indented_migration_content # 5 is line no.
        end

        private

        def migrate_command
          cmd = "bundle exec decko generate card:migration add_#{@codename}"
          cmd += " --force" if @force
          cmd
        end

        def indented_migration_content
          migration_file_content.lines.map do |line|
            " " * 4 + line
          end.join
        end

        def migration_file_content
          indent = " " * category.to_s.size
          <<-RUBY.strip_heredoc
            add_#{category} "#{remove_prefix @name}",
                #{indent} type_id: #{type_id},
                #{indent} to: "#{rule_card_name}"
          RUBY
        end

        def remove_prefix name
          name.sub(/^(?:#{category}):?_?\s*/, "")
        end

        def type_id
          "Card::#{type_codename.to_s.camelcase}ID"
        end
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
card-1.96.8 lib/card/tasks/card/file_card_creator/abstract_file_card/migration_file.rb
card-1.96.7 lib/card/tasks/card/file_card_creator/abstract_file_card/migration_file.rb
card-1.96.6 lib/card/tasks/card/file_card_creator/abstract_file_card/migration_file.rb
card-1.96.5 lib/card/tasks/card/file_card_creator/abstract_file_card/migration_file.rb
card-1.96.4 lib/card/tasks/card/file_card_creator/abstract_file_card/migration_file.rb
card-1.96.3 lib/card/tasks/card/file_card_creator/abstract_file_card/migration_file.rb
card-1.96.2 lib/card/tasks/card/file_card_creator/abstract_file_card/migration_file.rb
card-1.96.1 lib/card/tasks/card/file_card_creator/abstract_file_card/migration_file.rb
card-1.96.0 lib/card/tasks/card/file_card_creator/abstract_file_card/migration_file.rb
card-1.95.3 lib/card/tasks/card/file_card_creator/abstract_file_card/migration_file.rb
card-1.95.2 lib/card/tasks/card/file_card_creator/abstract_file_card/migration_file.rb
card-1.95.1 lib/card/tasks/card/file_card_creator/abstract_file_card/migration_file.rb
card-1.95.0 lib/card/tasks/card/file_card_creator/abstract_file_card/migration_file.rb
card-1.94.1 lib/card/tasks/card/file_card_creator/abstract_file_card/migration_file.rb
card-1.94.0 lib/card/tasks/card/file_card_creator/abstract_file_card/migration_file.rb
card-1.93.13 lib/card/tasks/card/file_card_creator/abstract_file_card/migration_file.rb
card-1.93.12 lib/card/tasks/card/file_card_creator/abstract_file_card/migration_file.rb
card-1.93.11 lib/card/tasks/card/file_card_creator/abstract_file_card/migration_file.rb
card-1.93.10 lib/card/tasks/card/file_card_creator/abstract_file_card/migration_file.rb
card-1.93.9 lib/card/tasks/card/file_card_creator/abstract_file_card/migration_file.rb