Module: PUNK::Validatable
Instance Attribute Summary collapse
Instance Method Summary
collapse
#validates_email, #validates_event, #validates_parse_id, #validates_phone, #validates_state, #validates_subdomain, #validates_url
Instance Attribute Details
#errors ⇒ Object
Returns the value of attribute errors.
15
16
17
|
# File 'lib/punk/helpers/validatable.rb', line 15
def errors
@errors
end
|
Instance Method Details
#default_validation_helpers_options(type) ⇒ Object
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/punk/helpers/validatable.rb', line 30
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) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/punk/helpers/validatable.rb', line 41
def get_column_value(name)
value =
begin
instance_variable_get(name)
rescue StandardError
nil
end
value ||=
begin
send(name)
rescue StandardError
nil
end
value
end
|
#valid? ⇒ Boolean
17
18
19
20
21
22
|
# File 'lib/punk/helpers/validatable.rb', line 17
def valid?
@errors ||= Sequel::Model::Errors.new
errors.clear
validate
errors.empty?
end
|
#validate ⇒ Object
24
|
# File 'lib/punk/helpers/validatable.rb', line 24
def validate; end
|
#validates_not_empty(atts, opts = Sequel::OPTS) ⇒ Object
26
27
28
|
# File 'lib/punk/helpers/validatable.rb', line 26
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
|