Sha256: 49d28606c0f78aa8f85fbd35343be2cbf372e1d40066b3aab8f1ccbee997d39e

Contents?: true

Size: 1.2 KB

Versions: 24

Compression:

Stored size: 1.2 KB

Contents

# Language Model
module KepplerLanguages
  class Language < ActiveRecord::Base
    include ActivityHistory
    include CloneRecord
    require 'csv'
    acts_as_list
    before_destroy :delete_yml

    include KepplerLanguages::Concerns::YmlFile

    validates_presence_of :name
    validates_uniqueness_of :name
    has_many :fields

    has_many :fields, dependent: :destroy, inverse_of: :language
    accepts_nested_attributes_for :fields, reject_if: :all_blank, allow_destroy: true

    
    # Fields for the search form in the navbar
    def self.search_field
      fields = ["name", "position", "deleted_at"]
      build_query(fields, :or, :cont)
    end

    def self.upload(file)
      CSV.foreach(file.path, headers: true) do |row|
        begin
          self.create! row.to_hash
        rescue => err
        end
      end
    end

    def self.sorter(params)
      params.each_with_index do |id, idx|
        self.find(id).update(position: idx.to_i+1)
      end
    end

    # Funcion para armar el query de ransack
    def self.build_query(fields, operator, conf)
      query = fields.join("_#{operator}_")
      query << "_#{conf}"
      query.to_sym
    end

    def install_yml
      create_yml
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
keppler-2.1.22 installer/core/rockets/keppler_languages/app/models/keppler_languages/language.rb
keppler-2.1.21 installer/core/rockets/keppler_languages/app/models/keppler_languages/language.rb
keppler-2.1.20 installer/core/rockets/keppler_languages/app/models/keppler_languages/language.rb
keppler-2.1.19 installer/core/rockets/keppler_languages/app/models/keppler_languages/language.rb
keppler-2.1.18 installer/core/rockets/keppler_languages/app/models/keppler_languages/language.rb
keppler-2.1.17 installer/core/rockets/keppler_languages/app/models/keppler_languages/language.rb
keppler-2.1.16 installer/core/rockets/keppler_languages/app/models/keppler_languages/language.rb
keppler-2.1.15 installer/core/rockets/keppler_languages/app/models/keppler_languages/language.rb
keppler-2.1.14 installer/core/rockets/keppler_languages/app/models/keppler_languages/language.rb
keppler-2.1.13 installer/core/rockets/keppler_languages/app/models/keppler_languages/language.rb
keppler-2.1.12 installer/core/rockets/keppler_languages/app/models/keppler_languages/language.rb
keppler-2.1.11 installer/core/rockets/keppler_languages/app/models/keppler_languages/language.rb
keppler-2.1.10 installer/core/rockets/keppler_languages/app/models/keppler_languages/language.rb
keppler-2.1.9 installer/core/rockets/keppler_languages/app/models/keppler_languages/language.rb
keppler-2.1.8 installer/core/rockets/keppler_languages/app/models/keppler_languages/language.rb
keppler-2.1.7 installer/core/rockets/keppler_languages/app/models/keppler_languages/language.rb
keppler-2.1.6 installer/core/rockets/keppler_languages/app/models/keppler_languages/language.rb
keppler-2.1.5 installer/core/rockets/keppler_languages/app/models/keppler_languages/language.rb
keppler-2.1.4 installer/core/rockets/keppler_languages/app/models/keppler_languages/language.rb
keppler-2.1.3 installer/core/rockets/keppler_languages/app/models/keppler_languages/language.rb