Class: KnowItAll::Base
- Inherits:
-
Object
- Object
- KnowItAll::Base
- Defined in:
- lib/know_it_all/base.rb
Direct Known Subclasses
Class Method Summary collapse
-
.assert(*args) ⇒ Object
DEPRECATED: Please use
validate
instead. - .inherited(subclass) ⇒ Object
- .validate(method_name, message = nil) ⇒ Object
- .validations ⇒ Object
- .validations=(validations) ⇒ Object
Instance Method Summary collapse
Class Method Details
.assert(*args) ⇒ Object
DEPRECATED: Please use validate
instead.
16 17 18 19 |
# File 'lib/know_it_all/base.rb', line 16 def self.assert(*args) warn "[DEPRECATION] `assert` is deprecated. Please use `validate` instead." validate(*args) end |
.inherited(subclass) ⇒ Object
11 12 13 |
# File 'lib/know_it_all/base.rb', line 11 def self.inherited(subclass) subclass.validations = validations.dup end |
.validate(method_name, message = nil) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/know_it_all/base.rb', line 21 def self.validate(method_name, = nil) if .nil? && defined?(I18n) class_names = StringHelper.underscore(self.to_s).split("/") = I18n.t(["policies", *class_names, method_name].join(".")) end validations[method_name] = end |
.validations ⇒ Object
3 4 5 |
# File 'lib/know_it_all/base.rb', line 3 def self.validations @validations ||= {} end |
.validations=(validations) ⇒ Object
7 8 9 |
# File 'lib/know_it_all/base.rb', line 7 def self.validations=(validations) @validations = validations end |
Instance Method Details
#errors ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/know_it_all/base.rb', line 29 def errors self.class.validations.each .reject { |method_name, _| self.send(method_name) } .map do |_, | if .respond_to?(:call) .call(self) else end end end |