Module: CompoundFormsLabelExtensions

Extended by:
ActiveSupport::Concern
Defined in:
app/models/concerns/compound_forms_label_extensions.rb

Instance Method Summary collapse

Instance Method Details

#compound_form_contents_languagesObject



80
81
82
83
84
85
86
87
88
89
# File 'app/models/concerns/compound_forms_label_extensions.rb', line 80

def compound_form_contents_languages
  if validatable_for_publishing?
    compound_form_contents.each do |cfc|
      if cfc.label.language != language
        errors.add :base, I18n.t("txt.models.label.compound_form_contents_language_error")
        break
      end
    end
  end
end

#compound_form_contents_self_referenceObject



91
92
93
94
95
96
97
98
# File 'app/models/concerns/compound_forms_label_extensions.rb', line 91

def compound_form_contents_self_reference
  if validatable_for_publishing?
    cfc_label_ids = compound_form_contents.map {|cfc| cfc.label_id }
    if cfc_label_ids.include? published_version_id
      errors.add :base, I18n.t("txt.models.label.compound_form_contents_self_reference_error")
    end
  end
end

#compound_form_contents_sizeObject



70
71
72
73
74
75
76
77
78
# File 'app/models/concerns/compound_forms_label_extensions.rb', line 70

def compound_form_contents_size
  if validatable_for_publishing?
    compound_forms.each do |cf|
      if cf.compound_form_contents.count < 2
        errors.add :base, I18n.t("txt.models.label.compound_form_contents_size_error")
      end
    end
  end
end

#compound_inObject



48
49
50
51
52
53
# File 'app/models/concerns/compound_forms_label_extensions.rb', line 48

def compound_in
  # FIXME: sort with database function
  CompoundForm::Base.joins(:compound_form_contents)
    .where(:compound_form_contents => { :label_id => id })
    .includes(:domain).map(&:domain).sort_by(&:value)
end

#inline_compound_form_originsObject

Serialized setters and getters (rn or , separated)



56
57
58
# File 'app/models/concerns/compound_forms_label_extensions.rb', line 56

def inline_compound_form_origins
  @inline_compound_form_origins || []
end

#inline_compound_form_origins=(value_collection) ⇒ Object



60
61
62
63
64
65
66
67
68
# File 'app/models/concerns/compound_forms_label_extensions.rb', line 60

def inline_compound_form_origins=(value_collection)
  # write to instance variable and write it on after_safe
  @inline_compound_form_origins ||= []

  value_collection.reject(&:blank?).each do |value|
    @inline_compound_form_origins << value.split(/\r\n|, */).map(&:strip).
        reject(&:blank?).uniq
  end
end