Module: Sequel::Plugins::RequireValidSchema
- Defined in:
- lib/sequel/plugins/require_valid_schema.rb
Overview
The require_valid_schema plugin makes Sequel raise or warn if attempting to set the dataset of a model class to a simple table, where the database supports schema parsing, but schema parsing does not work for the model’s table.
The plugin’s default behavior requires that all models that select from a single identifier have a valid table schema, if the database supports schema parsing. If the schema cannot be determined for such a model, an error is raised:
Sequel::Model.plugin :require_valid_schema
If you load the plugin with an argument of :warn, Sequel will warn instead of raising for such tables:
Sequel::Model.plugin :require_valid_schema, :warn
This can catch bugs where you expect models to have valid schema, but they do not. This setting only affects future attempts to set datasets in the current class and subclasses created in the future.
If you load the plugin with an argument of false, it will not require valid schema. This can be used in subclasses where you do not want to require valid schema, but the plugin must be loaded before a dataset with invalid schema is set:
Sequel::Model.plugin :require_valid_schema
InvalidSchemaAllowed = Class.new(Sequel::Model)
InvalidSchemaAllowed.plugin :require_valid_schema, false
class MyModel < InvalidSchemaAllowed
end
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.configure(model, setting = true) ⇒ Object
Modify the current model’s dataset selection, if the model has a dataset.
Class Method Details
.configure(model, setting = true) ⇒ Object
Modify the current model’s dataset selection, if the model has a dataset.
38 39 40 |
# File 'lib/sequel/plugins/require_valid_schema.rb', line 38 def self.configure(model, setting=true) model.instance_variable_set(:@require_valid_schema, setting) end |