Class: Dynabute::Util

Inherits:
Object
  • Object
show all
Defined in:
lib/dynabute/util.rb

Class Method Summary collapse

Class Method Details

.all_value_relation_namesObject



26
27
28
# File 'lib/dynabute/util.rb', line 26

def all_value_relation_names
  Dynabute::Field::TYPES.map{|t| Util.value_relation_name(t) }
end

.nested_attributable_presence_validator(id_attr, id_relation_accessor, halt: false) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/dynabute/util.rb', line 4

def nested_attributable_presence_validator(id_attr, id_relation_accessor, halt: false)
  return -> {
    attr = id_attr.to_sym
    if (persisted? && self[attr].nil?) || (new_record? && send(id_relation_accessor).nil?)
      errors[attr] << I18n.t('errors.messages.blank')
      return fail(:abort) if(halt)
    end
  }
end

.table_name_prefixObject



14
15
16
# File 'lib/dynabute/util.rb', line 14

def table_name_prefix
  'dynabute_'
end

.value_class_name(type) ⇒ Object



18
19
20
# File 'lib/dynabute/util.rb', line 18

def value_class_name(type)
  "Dynabute::Values::#{type.to_s.classify}Value"
end

.value_relation_name(type) ⇒ Object



22
23
24
# File 'lib/dynabute/util.rb', line 22

def value_relation_name(type)
  "#{type}_values".to_sym
end