Module: Inflectionable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/inflectionable.rb
Instance Method Summary collapse
- #candidates ⇒ Object
- #create_default_inflectional ⇒ Object
- #endings ⇒ Object
- #generate_inflectionals! ⇒ Object
- #inflectionals_attributes=(str) ⇒ Object
- #overwrite_inflectionals! ⇒ Object
Instance Method Details
#candidates ⇒ Object
30 31 32 |
# File 'app/models/concerns/inflectionable.rb', line 30 def candidates Inflectional::Base.candidates_for(base_form, language, inflectional_code) end |
#create_default_inflectional ⇒ Object
63 64 65 66 67 68 |
# File 'app/models/concerns/inflectionable.rb', line 63 def create_default_inflectional # ensure a matching inflectional exists if value && inflectionals.empty? inflectionals.create(:value => value) end end |
#endings ⇒ Object
26 27 28 |
# File 'app/models/concerns/inflectionable.rb', line 26 def endings Inflectional::Base.for_language_and_code(language, inflectional_code) end |
#generate_inflectionals! ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/models/concerns/inflectionable.rb', line 34 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
49 50 51 |
# File 'app/models/concerns/inflectionable.rb', line 49 def inflectionals_attributes=(str) @inflectionals_attributes = str.split("\r\n").uniq end |
#overwrite_inflectionals! ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'app/models/concerns/inflectionable.rb', line 53 def overwrite_inflectionals! return unless inflectionals_attributes transaction do inflectionals.delete_all inflectionals_attributes.each do |value| inflectionals.create!(value: value) end end end |