Module: Whiteprint

Defined in:
lib/whiteprint.rb,
lib/whiteprint/base.rb,
lib/whiteprint/model.rb,
lib/whiteprint/config.rb,
lib/whiteprint/railtie.rb,
lib/whiteprint/version.rb,
lib/whiteprint/migrator.rb,
lib/whiteprint/transform.rb,
lib/whiteprint/attributes.rb,
lib/whiteprint/explanation.rb,
lib/whiteprint/adapters/test.rb,
lib/whiteprint/has_whiteprint.rb,
lib/whiteprint/adapters/active_record.rb,
lib/whiteprint/adapters/active_record/migration.rb,
lib/whiteprint/adapters/active_record/has_and_belongs_to_many.rb

Defined Under Namespace

Modules: Adapters, Config, Explanation, HasWhiteprint, Migrator, Model Classes: Attribute, AttributeScope, Attributes, Base, Railtie, Transform

Constant Summary collapse

ADAPTERS =
{
  active_record:            Adapters::ActiveRecord,
  has_and_belongs_to_many:  Adapters::ActiveRecord::HasAndBelongsToMany,
  test:                     Adapters::Test,
  base:                     Base
}.freeze
VERSION =
'0.1.0'.freeze
@@models =
[]
@@plugins =
{}

Class Method Summary collapse

Class Method Details

.changed_whiteprintsObject



87
88
89
# File 'lib/whiteprint.rb', line 87

def changed_whiteprints
  whiteprints.select(&:changes?)
end

.config(&block) ⇒ Object



2
3
4
5
# File 'lib/whiteprint/config.rb', line 2

def self.config(&block)
  return Config unless block
  Config.instance_exec(Config, &block)
end

.modelsObject



74
75
76
77
78
79
80
81
# File 'lib/whiteprint.rb', line 74

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) ⇒ Object



70
71
72
# File 'lib/whiteprint.rb', line 70

def models=(models)
  @@models = models
end

.new(model, adapter: nil, **options) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/whiteprint.rb', line 55

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

.pluginsObject



91
92
93
# File 'lib/whiteprint.rb', line 91

def plugins
  @@plugins
end

.register_plugin(name, constant) ⇒ Object



95
96
97
# File 'lib/whiteprint.rb', line 95

def register_plugin(name, constant)
  @@plugins[name] = constant
end

.whiteprintsObject



83
84
85
# File 'lib/whiteprint.rb', line 83

def whiteprints
  models.map(&:whiteprint).compact
end