Class: EasySearch::Validations
- Inherits:
-
Object
- Object
- EasySearch::Validations
- Defined in:
- lib/easy_search/validations.rb
Class Method Summary collapse
-
.validate_class!(klass) ⇒ Object
called when a new EasySearch containing class is instantiated.
-
.validate_settings! ⇒ Object
called once the EasySearch module is included.
Class Method Details
.validate_class!(klass) ⇒ Object
called when a new EasySearch containing class is instantiated.
For example, ‘Search.users.with(“ryan heath”)’ would instantiate a new Search, setting the “users” part to the @klass variable. the following would ensure that the @klass variable is indeed valid.
25 26 27 28 |
# File 'lib/easy_search/validations.rb', line 25 def self.validate_class!(klass) raise( InvalidActiveRecordModel, InvalidActiveRecordModel. ) unless valid_model?(klass) raise( InvalidSettings, InvalidSettings. ) unless model_has_settings?(klass) end |
.validate_settings! ⇒ Object
called once the EasySearch module is included.
it ensures that any/all models in the settings hash exist and decend from ActiveRecord::Base
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/easy_search/validations.rb', line 7 def self.validate_settings! unless Setup.table_settings.blank? Setup.table_settings.keys.each do |klass| unless klass.to_s.classify.constantize.ancestors.include?(ActiveRecord::Base) raise( InvalidActiveRecordModel, InvalidActiveRecordModel. ) end end end rescue NameError raise $! raise( NoModelError, "you've specified a table in your `Setup.config' block that doesn't exist" ) end |