Module: HatTrick::ModelMethods

Extended by:
ActiveSupport::Concern
Defined in:
lib/hat_trick/model_methods.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#_dummyObject

so the dummy field will have something to set



7
8
9
# File 'lib/hat_trick/model_methods.rb', line 7

def _dummy
  @_dummy
end

Class Method Details

.clear_current_validation_group_for(klass) ⇒ Object



31
32
33
34
35
36
# File 'lib/hat_trick/model_methods.rb', line 31

def self.clear_current_validation_group_for(klass)
  unless validation_groups.nil?
    Rails.logger.debug "Clearing current validation groups for #{klass.to_s.underscore}"
    validation_groups.delete klass.to_s.underscore
  end
end

.current_validation_group_for(klass) ⇒ Object



26
27
28
29
# File 'lib/hat_trick/model_methods.rb', line 26

def self.current_validation_group_for(klass)
  return nil unless validation_groups
  validation_groups[klass.to_s.underscore]
end

.dynamic_validation_groupsObject



14
15
16
# File 'lib/hat_trick/model_methods.rb', line 14

def self.dynamic_validation_groups
  @dynamic_validation_groups ||= []
end

.set_current_validation_group_for(klass, validation_group_name, dynamic) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/hat_trick/model_methods.rb', line 18

def self.set_current_validation_group_for(klass, validation_group_name, dynamic)
  self.validation_groups ||= {}
  validation_groups[klass.to_s.underscore] = validation_group_name
  if dynamic && !dynamic_validation_groups.include?(validation_group_name)
    dynamic_validation_groups << validation_group_name
  end
end

Instance Method Details

#as_json_with_model_name(*args, &block) ⇒ Object



51
52
53
54
# File 'lib/hat_trick/model_methods.rb', line 51

def as_json_with_model_name(*args, &block)
  json = as_json_without_model_name(*args, &block)
  json.merge! :__name__ => self.class.to_s.underscore if json.respond_to?(:merge!)
end

#disable_validation_groupsObject



43
44
45
46
47
48
49
# File 'lib/hat_trick/model_methods.rb', line 43

def disable_validation_groups
  if respond_to?(:disable_validation_group)
    Rails.logger.debug "Disabling validation groups"
    disable_validation_group
  end
  HatTrick::ModelMethods.clear_current_validation_group_for(self.class)
end

#perform_validations_with_hat_trick(*args, &block) ⇒ Object



38
39
40
41
# File 'lib/hat_trick/model_methods.rb', line 38

def perform_validations_with_hat_trick(*args, &block)
  enable_current_validation_group
  perform_validations_without_hat_trick(*args, &block)
end