Sha256: 4d9cb7369208c3ea877a77fc91dac91dee7546106f580c0ed41951dc9f7bc68a

Contents?: true

Size: 694 Bytes

Versions: 1

Compression:

Stored size: 694 Bytes

Contents

# encoding: utf-8
require "yaml"

module Sunrise
  class YmlLocale
    attr_accessor :locale

    def initialize(locale)
      @locale = locale
    end
    
    def file_path
      Rails.root.join("config/locales/#{@locale}.yml")
    end
    
    def get_data
      text = ''
      
      f = File.open(file_path, 'r')
      f.each_line { |line| text += line }
      f.close
      
      text
    end
    
    def set_data(text)
      if valid?(text)
        File.open(file_path, 'w') {|f| f.write(text) }
      else
        false
      end
    end
    
    def valid?(text)
      begin
        YAML.load(text)
        true
      rescue Exception => e
        false
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sunrise-locales-0.1.0 lib/sunrise/locales/yml_locale.rb