module PUNK::Validatable

Attributes

errors[RW]

Public Instance Methods

default_validation_helpers_options(type) click to toggle source
# File lib/punk/helpers/validatable.rb, line 31
def default_validation_helpers_options(type)
  case type
  when :not_empty
    {
      message: -> { "is empty" }
    }
  else
    Sequel::Plugins::ValidationHelpers::DEFAULT_OPTIONS[type]
  end
end
get_column_value(name) click to toggle source
# File lib/punk/helpers/validatable.rb, line 42
def get_column_value(name)
  value =
    begin
      instance_variable_get(name)
    rescue
      nil
    end
  value ||=
    begin
      send(name)
    rescue
      nil
    end
  value
end
valid?() click to toggle source
# File lib/punk/helpers/validatable.rb, line 17
def valid?
  @errors ||= Sequel::Model::Errors.new
  errors.clear
  validate
  errors.empty?
end
validate() click to toggle source
# File lib/punk/helpers/validatable.rb, line 24
def validate
end
validates_not_empty(atts, opts = Sequel::OPTS) click to toggle source
# File lib/punk/helpers/validatable.rb, line 27
def validates_not_empty(atts, opts = Sequel::OPTS)
  validatable_attributes_for_type(:not_empty, atts, opts) { |_a, v, m| validation_error_message(m) if v.blank? }
end