module Whiteprint

Constants

ADAPTERS
VERSION

Public Class Methods

changed_whiteprints() click to toggle source
# File lib/whiteprint.rb, line 89
def changed_whiteprints
  whiteprints.select(&:changes?)
end
config(&block) click to toggle source
# File lib/whiteprint/config.rb, line 2
def self.config(&block)
  return Config unless block
  Config.instance_exec(Config, &block)
end
migrate(cli, separately:) click to toggle source
# File lib/whiteprint.rb, line 93
def migrate(cli, separately:)
  changed_whiteprints.group_by(&:transformer).map do |adapter, whiteprints|
    if separately
      cli.say 'Processing as separate migrations...'
      whiteprints.each do |whiteprint|
        cli.say whiteprint.explanation
        migration_path = adapter.generate_migration(*adapter.migration_params(cli), [whiteprint.changes_tree])
        `git add #{migration_path}` if Whiteprint.config.add_migration_to_git
      end
    else
      cli.say 'Processing as a single migration...'
      migration_path = adapter.generate_migration(*adapter.migration_params(cli), whiteprints.map(&:changes_tree))
      `git add #{migration_path}` if Whiteprint.config.add_migration_to_git
    end

    adapter.migrate
  end
end
models() click to toggle source
# File lib/whiteprint.rb, line 76
def models
  @@models.select  { |model| model.is_a?(Class) }
          .reject  { |model| model.respond_to?(:abstract_class) && model.abstract_class }
          .sort_by { |model| model.respond_to?(:table_name) && model.table_name || model.name || model.object_id.to_s }
          .sort    { |a, b|  -1 * (a <=> b).to_i }
          .uniq    { |model| model.respond_to?(:table_name) && model.table_name || model.name || model.object_id.to_s }
          .sort_by { |model| model.name || model.object_id.to_s }
end
models=(models) click to toggle source
# File lib/whiteprint.rb, line 72
def models=(models)
  @@models = models
end
new(model, adapter: nil, **options) click to toggle source
# File lib/whiteprint.rb, line 57
def new(model, adapter: nil, **options)
  if adapter
    ADAPTERS[adapter].new(model, **options)
  else
    adapter = ADAPTERS.find do |_, whiteprint|
      whiteprint.applicable?(model)
    end

    adapter[-1].new(model, **options)
  end
end
plugins() click to toggle source
# File lib/whiteprint.rb, line 112
def plugins
  @@plugins
end
register_plugin(name, constant) click to toggle source
# File lib/whiteprint.rb, line 116
def register_plugin(name, constant)
  @@plugins[name] = constant
end
whiteprints() click to toggle source
# File lib/whiteprint.rb, line 85
def whiteprints
  models.map(&:whiteprint).compact
end