Module: Inflectionable

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

Instance Method Summary collapse

Instance Method Details

#candidatesObject



20
21
22
# File 'app/models/concerns/inflectionable.rb', line 20

def candidates
  Inflectional::Base.candidates_for(base_form, language, inflectional_code)
end

#create_default_inflectionalObject



53
54
55
56
57
58
# File 'app/models/concerns/inflectionable.rb', line 53

def create_default_inflectional
  # ensure a matching inflectional exists
  if value && inflectionals.where(:value => value).none?
    inflectionals.create(:value => value)
  end
end

#endingsObject



16
17
18
# File 'app/models/concerns/inflectionable.rb', line 16

def endings
  Inflectional::Base.for_language_and_code(language, inflectional_code)
end

#generate_inflectionals!Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/models/concerns/inflectionable.rb', line 24

def generate_inflectionals!
  return send(Inflectional::Base.name.to_relation_name) if base_form.blank?

  candidates.each do |candidate|
    if candidate && inflectionals.where(value: candidate).none?
      send(Inflectional::Base.name.to_relation_name).create!(value: candidate)
    end
  end

  # self.base_form = new_base_form
  save(validate: false)

  inflectionals
end

#inflectionals_attributes=(str) ⇒ Object



39
40
41
# File 'app/models/concerns/inflectionable.rb', line 39

def inflectionals_attributes=(str)
  @inflectionals_attributes = str.split("\r\n").uniq
end

#overwrite_inflectionals!Object



43
44
45
46
47
48
49
50
51
# File 'app/models/concerns/inflectionable.rb', line 43

def overwrite_inflectionals!
  return unless inflectionals_attributes
  transaction do
    inflectionals.delete_all
    inflectionals_attributes.each do |value|
      inflectionals.create!(value: value)
    end
  end
end