Class: GacoCms::FieldValue

Inherits:
ApplicationRecord show all
Includes:
BuddyTranslatable
Defined in:
app/models/gaco_cms/field_value.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

#activestorage_url, #cache_key_locale, human_name

Class Method Details

.all_or_new_for(field, group_no) ⇒ Object



47
48
49
50
# File 'app/models/gaco_cms/field_value.rb', line 47

def self.all_or_new_for(field, group_no)
  items = where(field: field).where(group_no: group_no)
  items.any? ? items.ordered : [items.new]
end

.group_nos_for(group) ⇒ Object



43
44
45
# File 'app/models/gaco_cms/field_value.rb', line 43

def self.group_nos_for(group)
  for_group(group).pluck(:group_no).uniq.sort
end

.groupedObject



52
53
54
55
56
57
# File 'app/models/gaco_cms/field_value.rb', line 52

def self.grouped
  groups = reorder(group_no: :asc).pluck('distinct(group_no)')
  groups.map do |g_no|
    where(group_no: g_no).ordered
  end
end

Instance Method Details

#the_valueObject



67
68
69
# File 'app/models/gaco_cms/field_value.rb', line 67

def the_value
  ShortcodeParser.call(value, record)
end

#value_for_inputObject



59
60
61
62
63
64
65
# File 'app/models/gaco_cms/field_value.rb', line 59

def value_for_input
  @value_for_input ||= begin
    return new_record? ? def_value : value unless translatable

    new_record? ? def_value_data.to_json : value_data.to_json
  end
end