-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validate configuration #32
Conversation
def model(name) | ||
model_config = ModelConfig.new(name).tap do |config| | ||
yield(config) | ||
Rails.application.config.to_prepare { config.validate! } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the models are not loaded here yet. so model.column_names
would raise for example. that's why I'm scheduling them for Rails to pick them up as soon as you init the server or so
example if an invalid attribute is specified and you boot up Rails:
Exiting
/Users/simon/r/hotsheet/lib/hotsheet/configuration.rb:49:in `block in validate_attribute_existence': Attribute 'test' doesn't exist on model 'Post' (RuntimeError)
from /Users/simon/r/hotsheet/lib/hotsheet/configuration.rb:47:in `each'
from /Users/simon/r/hotsheet/lib/hotsheet/configuration.rb:47:in `validate_attribute_existence'
from /Users/simon/r/hotsheet/lib/hotsheet/configuration.rb:32:in `validate!'
from /Users/simon/r/hotsheet/lib/hotsheet/configuration.rb:16:in `block (2 levels) in model'
32c1029
to
30dc01e
Compare
|
9a35963
to
e7bc0af
Compare
end | ||
|
||
def validate! | ||
return unless ActiveRecord::Base.connection.table_exists?(model_class.table_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we currently only support ActiveRecord models (due to .column_names
) calls mainly. so this should be fine
e7bc0af
to
670f80c
Compare
No description provided.