Sha256: 62347a88df5df1cb7e8379464579aba547f5cdf95367f718b737db0c3167c23b

Contents?: true

Size: 1.01 KB

Versions: 37

Compression:

Stored size: 1.01 KB

Contents

module TinyMCE::Rails
  class ConfigurationFile
    attr_reader :path

    def initialize(path)
      @path = path
    end

    def configuration
      @configuration = load_configuration if reload?
      @configuration
    end

    def reload?
      @configuration.nil? || (reloadable? && changed?)
    end

    def changed?
      @last_loaded != last_updated
    end

  private
    def reloadable?
      !::Rails.application.config.cache_classes
    end

    def last_updated
      File.exist?(path) && File.mtime(path)
    end

    def load_configuration
      @last_loaded = last_updated

      return Configuration.new_with_defaults if !File.exist?(path)

      options = load_yaml(path)

      if options && options.has_key?('default')
        MultipleConfiguration.new(options)
      else
        Configuration.new_with_defaults(options)
      end
    end

    def load_yaml(path)
      result = ERB.new(IO.read(path)).result
      YAML.respond_to?(:unsafe_load) ? YAML.unsafe_load(result) : YAML.load(result)
    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
tinymce-rails-7.6.0 lib/tinymce/rails/configuration_file.rb
tinymce-rails-7.5.1 lib/tinymce/rails/configuration_file.rb
tinymce-rails-7.5.0 lib/tinymce/rails/configuration_file.rb
tinymce-rails-6.8.5 lib/tinymce/rails/configuration_file.rb
tinymce-rails-7.4.1 lib/tinymce/rails/configuration_file.rb
tinymce-rails-7.4.0 lib/tinymce/rails/configuration_file.rb
tinymce-rails-7.3.0 lib/tinymce/rails/configuration_file.rb
tinymce-rails-7.2.1 lib/tinymce/rails/configuration_file.rb
tinymce-rails-6.8.4 lib/tinymce/rails/configuration_file.rb
tinymce-rails-7.2.0 lib/tinymce/rails/configuration_file.rb
tinymce-rails-7.1.2.1 lib/tinymce/rails/configuration_file.rb
tinymce-rails-7.1.2 lib/tinymce/rails/configuration_file.rb
tinymce-rails-7.0.1 lib/tinymce/rails/configuration_file.rb
tinymce-rails-7.0.0.1 lib/tinymce/rails/configuration_file.rb
tinymce-rails-6.8.3 lib/tinymce/rails/configuration_file.rb
tinymce-rails-6.8.2 lib/tinymce/rails/configuration_file.rb
tinymce-rails-6.8.1 lib/tinymce/rails/configuration_file.rb
tinymce-rails-6.8.0 lib/tinymce/rails/configuration_file.rb
tinymce-rails-5.10.9 lib/tinymce/rails/configuration_file.rb
tinymce-rails-6.7.2 lib/tinymce/rails/configuration_file.rb