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.1'.freeze
- @@models =
[]
- @@plugins =
{}
Class Method Summary
collapse
Class Method Details
.changed_whiteprints ⇒ Object
89
90
91
|
# File 'lib/whiteprint.rb', line 89
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
|
.migrate(cli, separately:) ⇒ Object
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# 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 ⇒ Object
76
77
78
79
80
81
82
83
|
# 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) ⇒ Object
72
73
74
|
# File 'lib/whiteprint.rb', line 72
def models=(models)
@@models = models
end
|
.new(model, adapter: nil, **options) ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
|
# 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 ⇒ Object
112
113
114
|
# File 'lib/whiteprint.rb', line 112
def plugins
@@plugins
end
|
.register_plugin(name, constant) ⇒ Object
116
117
118
|
# File 'lib/whiteprint.rb', line 116
def register_plugin(name, constant)
@@plugins[name] = constant
end
|
.whiteprints ⇒ Object
85
86
87
|
# File 'lib/whiteprint.rb', line 85
def whiteprints
models.map(&:whiteprint).compact
end
|