Module: Dbwatcher::Storage::Concerns::Validatable
- Included in:
- QueryStorage, SessionStorage, TableStorage
- Defined in:
- lib/dbwatcher/storage/concerns/validatable.rb
Overview
Provides validation capabilities for storage classes
This concern adds common validation methods and patterns used across different storage implementations.
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#valid_id?(id) ⇒ Boolean
Checks if an ID is valid.
-
#valid_name?(name) ⇒ Boolean
Checks if a name is valid.
-
#validate_id!(id) ⇒ void
Validates that an ID is present and valid.
-
#validate_name!(name) ⇒ void
Validates that a name is present and valid.
-
#validate_presence!(data, *attributes) ⇒ void
Validates presence of required attributes.
Class Method Details
.included(base) ⇒ Object
21 22 23 |
# File 'lib/dbwatcher/storage/concerns/validatable.rb', line 21 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#valid_id?(id) ⇒ Boolean
Checks if an ID is valid
84 85 86 |
# File 'lib/dbwatcher/storage/concerns/validatable.rb', line 84 def valid_id?(id) !id.nil? && !id.to_s.strip.empty? end |
#valid_name?(name) ⇒ Boolean
Checks if a name is valid
92 93 94 |
# File 'lib/dbwatcher/storage/concerns/validatable.rb', line 92 def valid_name?(name) !name.nil? && !name.to_s.strip.empty? end |
#validate_id!(id) ⇒ void
This method returns an undefined value.
Validates that an ID is present and valid
63 64 65 66 67 |
# File 'lib/dbwatcher/storage/concerns/validatable.rb', line 63 def validate_id!(id) return unless id.nil? || id.to_s.strip.empty? raise ValidationError, "ID cannot be nil or empty" end |
#validate_name!(name) ⇒ void
This method returns an undefined value.
Validates that a name is present and valid
74 75 76 77 78 |
# File 'lib/dbwatcher/storage/concerns/validatable.rb', line 74 def validate_name!(name) return unless name.nil? || name.to_s.strip.empty? raise ValidationError, "Name cannot be nil or empty" end |
#validate_presence!(data, *attributes) ⇒ void
This method returns an undefined value.
Validates presence of required attributes
48 49 50 51 52 53 54 55 56 |
# File 'lib/dbwatcher/storage/concerns/validatable.rb', line 48 def validate_presence!(data, *attributes) attrs_to_check = attributes.any? ? attributes : self.class.required_attributes attrs_to_check.each do |attr| next if data.key?(attr) && !blank_value?(data[attr]) raise ValidationError, "#{attr} is required but was #{data[attr].inspect}" end end |