Sha256: 181465cbceeeb94db682812cfd6a9f15a176be5a0999d77b2910fea8566bc7d2

Contents?: true

Size: 1006 Bytes

Versions: 65

Compression:

Stored size: 1006 Bytes

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.exists?(path) && File.mtime(path)
    end
    
    def load_configuration
      @last_loaded = last_updated
      
      return Configuration.new_with_defaults if !File.exists?(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)
      YAML::load(ERB.new(IO.read(path)).result)
    end
  end
end

Version data entries

65 entries across 65 versions & 1 rubygems

Version Path
tinymce-rails-4.6.7 lib/tinymce/rails/configuration_file.rb
tinymce-rails-4.6.6 lib/tinymce/rails/configuration_file.rb
tinymce-rails-4.6.5 lib/tinymce/rails/configuration_file.rb
tinymce-rails-4.6.4 lib/tinymce/rails/configuration_file.rb
tinymce-rails-4.6.3 lib/tinymce/rails/configuration_file.rb
tinymce-rails-4.6.2 lib/tinymce/rails/configuration_file.rb
tinymce-rails-4.6.1 lib/tinymce/rails/configuration_file.rb
tinymce-rails-4.6.0 lib/tinymce/rails/configuration_file.rb
tinymce-rails-4.5.7 lib/tinymce/rails/configuration_file.rb
tinymce-rails-4.5.6 lib/tinymce/rails/configuration_file.rb
tinymce-rails-4.5.5 lib/tinymce/rails/configuration_file.rb
tinymce-rails-4.5.4 lib/tinymce/rails/configuration_file.rb
tinymce-rails-4.5.3 lib/tinymce/rails/configuration_file.rb
tinymce-rails-4.5.2 lib/tinymce/rails/configuration_file.rb
tinymce-rails-4.5.1 lib/tinymce/rails/configuration_file.rb
tinymce-rails-4.5.0 lib/tinymce/rails/configuration_file.rb
tinymce-rails-4.4.3 lib/tinymce/rails/configuration_file.rb
tinymce-rails-4.4.2 lib/tinymce/rails/configuration_file.rb
tinymce-rails-4.4.1 lib/tinymce/rails/configuration_file.rb
tinymce-rails-4.4.0 lib/tinymce/rails/configuration_file.rb