Class: Mv::Core::Validation::Base

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations, Comparable
Defined in:
lib/mv/core/validation/base.rb

Direct Known Subclasses

Absence, BaseCollection, Custom, Length, Presence, Uniqueness

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table_name, column_name, options) ⇒ Base

Returns a new instance of Base.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 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

Instance Attribute Details

#allow_blankObject (readonly)

Returns the value of attribute allow_blank.



8
9
10
# File 'lib/mv/core/validation/base.rb', line 8

def allow_blank
  @allow_blank
end

#allow_nilObject (readonly)

Returns the value of attribute allow_nil.



8
9
10
# File 'lib/mv/core/validation/base.rb', line 8

def allow_nil
  @allow_nil
end

#asObject (readonly)

Returns the value of attribute as.



8
9
10
# File 'lib/mv/core/validation/base.rb', line 8

def as
  @as
end

#column_nameObject (readonly)

Returns the value of attribute column_name.



8
9
10
# File 'lib/mv/core/validation/base.rb', line 8

def column_name
  @column_name
end

#create_trigger_nameObject (readonly)

Returns the value of attribute create_trigger_name.



8
9
10
# File 'lib/mv/core/validation/base.rb', line 8

def create_trigger_name
  @create_trigger_name
end

#messageObject (readonly)

Returns the value of attribute message.



8
9
10
# File 'lib/mv/core/validation/base.rb', line 8

def message
  @message
end

#onObject (readonly)

Returns the value of attribute on.



8
9
10
# File 'lib/mv/core/validation/base.rb', line 8

def on
  @on
end

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/mv/core/validation/base.rb', line 8

def options
  @options
end

#table_nameObject (readonly)

Returns the value of attribute table_name.



8
9
10
# File 'lib/mv/core/validation/base.rb', line 8

def table_name
  @table_name
end

#update_trigger_nameObject (readonly)

Returns the value of attribute update_trigger_name.



8
9
10
# File 'lib/mv/core/validation/base.rb', line 8

def update_trigger_name
  @update_trigger_name
end

Instance Method Details

#<=>(other_validation) ⇒ Object



40
41
42
# 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?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/mv/core/validation/base.rb', line 48

def create?
  [:save, :create].include?(on.try(:to_sym))
end

#full_messageObject



52
53
54
# File 'lib/mv/core/validation/base.rb', line 52

def full_message
  compose_full_message(message)
end

#to_aObject



35
36
37
38
# 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?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/mv/core/validation/base.rb', line 44

def update?
  [:save, :update].include?(on.try(:to_sym))
end