class Mv::Core::Presenter::Validation::Base
Attributes
validation[R]
Public Class Methods
new(validation)
click to toggle source
# File lib/mv/core/presenter/validation/base.rb, line 10 def initialize(validation) @validation = validation end
Public Instance Methods
to_s()
click to toggle source
# File lib/mv/core/presenter/validation/base.rb, line 14 def to_s options_as_str = options.blank? ? 'true' : "{ #{options_str} }" "validates(\"#{table_name}\", \"#{column_name}\", #{validation_type}: #{options_as_str})".squish end
Private Instance Methods
array_to_str(value)
click to toggle source
# File lib/mv/core/presenter/validation/base.rb, line 43 def array_to_str value "[#{value.collect{ |value| value_to_str(value) }.join(', ')}]" end
date_to_str(value)
click to toggle source
# File lib/mv/core/presenter/validation/base.rb, line 67 def date_to_str value "Date.new(#{value.strftime("%Y, %-m, %-d")})" end
datetime_to_str(value)
click to toggle source
# File lib/mv/core/presenter/validation/base.rb, line 63 def datetime_to_str value "DateTime.new(#{value.utc.strftime("%Y, %-m, %-d, %-H, %-M, %-S")})" end
escaped_string(value)
click to toggle source
# File lib/mv/core/presenter/validation/base.rb, line 55 def escaped_string value value.gsub(/'/, %q(\\\')) end
options_str()
click to toggle source
# File lib/mv/core/presenter/validation/base.rb, line 25 def options_str options.collect do |key, value| "#{key}: #{value_to_str(value)}" end.join(', ') end
range_to_str(value)
click to toggle source
# File lib/mv/core/presenter/validation/base.rb, line 47 def range_to_str value [ value_to_str(value.first), value.exclude_end? ? '...' : '..', value_to_str(value.last) ].join end
time_to_str(value)
click to toggle source
# File lib/mv/core/presenter/validation/base.rb, line 59 def time_to_str value "Time.new(#{value.strftime("%Y, %-m, %-d, %-H, %-M, %-S")})" end
validation_type()
click to toggle source
# File lib/mv/core/presenter/validation/base.rb, line 21 def validation_type validation.class.name.demodulize.underscore end
value_to_str(value)
click to toggle source
# File lib/mv/core/presenter/validation/base.rb, line 31 def value_to_str value return ":#{value}" if value.is_a?(Symbol) return time_to_str(value) if value.is_a?(Time) return datetime_to_str(value) if value.is_a?(DateTime) return date_to_str(value) if value.is_a?(Date) return range_to_str(value) if value.is_a?(Range) return array_to_str(value) if value.is_a?(Array) return "'#{escaped_string(value)}'" if value.is_a?(String) return "/#{value.source}/" if value.is_a?(Regexp) value.to_s end