Skip to content
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

Merged
merged 2 commits into from
Nov 15, 2024
Merged

Validate configuration #32

merged 2 commits into from
Nov 15, 2024

Conversation

simon-isler
Copy link
Member

@simon-isler simon-isler commented Nov 12, 2024

No description provided.

@simon-isler simon-isler self-assigned this Nov 12, 2024
@simon-isler simon-isler changed the base branch from main to feature/fix-configuration November 12, 2024 17:15
def model(name)
model_config = ModelConfig.new(name).tap do |config|
yield(config)
Rails.application.config.to_prepare { config.validate! }
Copy link
Member Author

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'

@simon-isler simon-isler marked this pull request as ready for review November 12, 2024 17:19
@simon-isler simon-isler requested a review from a team as a code owner November 12, 2024 17:19
@simon-isler
Copy link
Member Author

simon-isler commented Nov 12, 2024

tests are WIP

end

def validate!
return unless ActiveRecord::Base.connection.table_exists?(model_class.table_name)
Copy link
Member Author

@simon-isler simon-isler Nov 12, 2024

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

Base automatically changed from feature/fix-configuration to main November 14, 2024 18:05
@simon-isler simon-isler merged commit 561ee17 into main Nov 15, 2024
2 of 3 checks passed
@simon-isler simon-isler deleted the feature/validate-config branch November 15, 2024 06:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants