class Mv::Core::Validation::Base

Attributes

allow_blank[R]
allow_nil[R]
as[R]
column_name[R]
create_trigger_name[R]
message[R]
on[R]
options[R]
table_name[R]
update_trigger_name[R]

Public Class Methods

new(table_name, column_name, options) click to toggle source
# File lib/mv/core/validation/base.rb, line 19
def initialize table_name, column_name, options
  @table_name = table_name
  @column_name = column_name
  @options = options

  options.with_indifferent_access.tap do |options|
    @message = options[:message] || default_message
    @as = options[:as] || default_as
    @on = options[:on] || default_on
    @create_trigger_name = options[:create_trigger_name] || default_create_trigger_name
    @update_trigger_name = options[:update_trigger_name] || default_update_trigger_name
    @allow_nil = options[:allow_nil].nil? ? default_allow_nil : options[:allow_nil]
    @allow_blank = options[:allow_blank].nil? ? default_allow_blank : options[:allow_blank]
  end
end

Public Instance Methods

<=>(other_validation) click to toggle source
# File lib/mv/core/validation/base.rb, line 40
def <=> other_validation
  [self.class.name, to_a] <=> [other_validation.class.name, other_validation.to_a]
end
create?() click to toggle source
# File lib/mv/core/validation/base.rb, line 48
def create?
  [:save, :create].include?(on.try(:to_sym))
end
full_message() click to toggle source
# File lib/mv/core/validation/base.rb, line 52
def full_message
  compose_full_message(message)
end
to_a() click to toggle source
# File lib/mv/core/validation/base.rb, line 35
def to_a
  [table_name.to_s, column_name.to_s, message.to_s, on.to_s, create_trigger_name.to_s,
   update_trigger_name.to_s, allow_nil, allow_blank, as.to_s]
end
update?() click to toggle source
# File lib/mv/core/validation/base.rb, line 44
def update?
  [:save, :update].include?(on.try(:to_sym))
end

Protected Instance Methods

available_as() click to toggle source
# File lib/mv/core/validation/base.rb, line 58
def available_as
  [:trigger]
end
available_on() click to toggle source
# File lib/mv/core/validation/base.rb, line 62
def available_on
  [:save, :update, :create]
end
compose_full_message(message) click to toggle source
# File lib/mv/core/validation/base.rb, line 94
def compose_full_message message
  "#{column_name.to_s} #{message}"
end
default_allow_blank() click to toggle source
# File lib/mv/core/validation/base.rb, line 90
def default_allow_blank
  false
end
default_allow_nil() click to toggle source
# File lib/mv/core/validation/base.rb, line 86
def default_allow_nil
  false
end
default_as() click to toggle source
# File lib/mv/core/validation/base.rb, line 74
def default_as
  :trigger
end
default_create_trigger_name() click to toggle source
# File lib/mv/core/validation/base.rb, line 78
def default_create_trigger_name
  "trg_mv_#{table_name}_ins" if create? && trigger?
end
default_message() click to toggle source
# File lib/mv/core/validation/base.rb, line 66
def default_message
  "#{self.class.name.split('::').last} violated on the table #{table_name} column #{column_name}"
end
default_on() click to toggle source
# File lib/mv/core/validation/base.rb, line 70
def default_on
  :save if trigger?
end
default_update_trigger_name() click to toggle source
# File lib/mv/core/validation/base.rb, line 82
def default_update_trigger_name
  "trg_mv_#{table_name}_upd" if update? && trigger?
end

Private Instance Methods

trigger?() click to toggle source
# File lib/mv/core/validation/base.rb, line 100
def trigger?
  as.try(:to_sym) == :trigger
end