Sha256: 33ede4fbfc603e4a6de8714ea2be3bf7faa17a78ee5677be5f704f0027d9a318

Contents?: true

Size: 1.41 KB

Versions: 31

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

31 entries across 31 versions & 1 rubygems

Version Path
card-1.104.2 lib/card/file_card_creator/abstract_file_card/migration_file.rb
card-1.104.1 lib/card/file_card_creator/abstract_file_card/migration_file.rb
card-1.104.0 lib/card/file_card_creator/abstract_file_card/migration_file.rb
card-1.103.4 lib/card/file_card_creator/abstract_file_card/migration_file.rb
card-1.103.3 lib/card/file_card_creator/abstract_file_card/migration_file.rb
card-1.103.2 lib/card/tasks/card/file_card_creator/abstract_file_card/migration_file.rb
card-1.103.1 lib/card/tasks/card/file_card_creator/abstract_file_card/migration_file.rb
card-1.103.0 lib/card/tasks/card/file_card_creator/abstract_file_card/migration_file.rb
card-1.101.7 lib/card/tasks/card/file_card_creator/abstract_file_card/migration_file.rb
card-1.102.0 lib/card/tasks/card/file_card_creator/abstract_file_card/migration_file.rb
card-1.101.6 lib/card/tasks/card/file_card_creator/abstract_file_card/migration_file.rb
card-1.101.5 lib/card/tasks/card/file_card_creator/abstract_file_card/migration_file.rb
card-1.101.4 lib/card/tasks/card/file_card_creator/abstract_file_card/migration_file.rb
card-1.101.3 lib/card/tasks/card/file_card_creator/abstract_file_card/migration_file.rb
card-1.101.2 lib/card/tasks/card/file_card_creator/abstract_file_card/migration_file.rb
card-1.101.1 lib/card/tasks/card/file_card_creator/abstract_file_card/migration_file.rb
card-1.101.0 lib/card/tasks/card/file_card_creator/abstract_file_card/migration_file.rb
card-1.100.0 lib/card/tasks/card/file_card_creator/abstract_file_card/migration_file.rb
card-1.99.6 lib/card/tasks/card/file_card_creator/abstract_file_card/migration_file.rb
card-1.99.5 lib/card/tasks/card/file_card_creator/abstract_file_card/migration_file.rb