Sha256: 4728c8c5462ac857e438a47ea0ca441879e7b19fc1ad07d4ef8d2dfff32a5a69

Contents?: true

Size: 1.19 KB

Versions: 24

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

# HtmlFile Module
module KepplerLanguages
  module Concerns
    module YmlFile
      extend ActiveSupport::Concern

      def create_yml
        file = File.open("#{url}/config/locales/kl.#{name}.yml", "w")
        file.puts("#{name}: \n");
        file.puts("  keppler_languages: \n");
        file.close
        true
      end

      def delete_yml
        file = "#{url}/config/locales/kl.#{name}.yml"
        File.delete(file) if File.exist?(file)
        true
      end

      def update_yml(yml)
        file = "#{url}/config/locales/kl.#{name}.yml"
        obj = Language.find(id)
        old_name = "#{url}/config/locales/kl.#{obj.name}.yml"
        new_name = "#{url}/config/locales/kl.#{yml[:name]}.yml"

        yml_file = File.readlines(file)

        head_idx = 0

        yml_file.each do |i|
          head_idx = yml_file.find_index(i) if i.include?("#{obj.name}:")
        end

        yml_file[head_idx] = "#{yml[:name]}:\n"
        yml_file = yml_file.join('')
        File.write(file, yml_file)
        File.rename(old_name, new_name)
        true
      end

      private

      def url
        "#{Rails.root}/rockets/keppler_languages"
      end
    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/concerns/yml_file.rb
keppler-2.1.21 installer/core/rockets/keppler_languages/app/models/keppler_languages/concerns/yml_file.rb
keppler-2.1.20 installer/core/rockets/keppler_languages/app/models/keppler_languages/concerns/yml_file.rb
keppler-2.1.19 installer/core/rockets/keppler_languages/app/models/keppler_languages/concerns/yml_file.rb
keppler-2.1.18 installer/core/rockets/keppler_languages/app/models/keppler_languages/concerns/yml_file.rb
keppler-2.1.17 installer/core/rockets/keppler_languages/app/models/keppler_languages/concerns/yml_file.rb
keppler-2.1.16 installer/core/rockets/keppler_languages/app/models/keppler_languages/concerns/yml_file.rb
keppler-2.1.15 installer/core/rockets/keppler_languages/app/models/keppler_languages/concerns/yml_file.rb
keppler-2.1.14 installer/core/rockets/keppler_languages/app/models/keppler_languages/concerns/yml_file.rb
keppler-2.1.13 installer/core/rockets/keppler_languages/app/models/keppler_languages/concerns/yml_file.rb
keppler-2.1.12 installer/core/rockets/keppler_languages/app/models/keppler_languages/concerns/yml_file.rb
keppler-2.1.11 installer/core/rockets/keppler_languages/app/models/keppler_languages/concerns/yml_file.rb
keppler-2.1.10 installer/core/rockets/keppler_languages/app/models/keppler_languages/concerns/yml_file.rb
keppler-2.1.9 installer/core/rockets/keppler_languages/app/models/keppler_languages/concerns/yml_file.rb
keppler-2.1.8 installer/core/rockets/keppler_languages/app/models/keppler_languages/concerns/yml_file.rb
keppler-2.1.7 installer/core/rockets/keppler_languages/app/models/keppler_languages/concerns/yml_file.rb
keppler-2.1.6 installer/core/rockets/keppler_languages/app/models/keppler_languages/concerns/yml_file.rb
keppler-2.1.5 installer/core/rockets/keppler_languages/app/models/keppler_languages/concerns/yml_file.rb
keppler-2.1.4 installer/core/rockets/keppler_languages/app/models/keppler_languages/concerns/yml_file.rb
keppler-2.1.3 installer/core/rockets/keppler_languages/app/models/keppler_languages/concerns/yml_file.rb