Sha256: a7dcb94ca1ae9d96f9ecf14ab02f0c130e9ae477768860df5141aefeb7aa8cbd

Contents?: true

Size: 1.04 KB

Versions: 18

Compression:

Stored size: 1.04 KB

Contents

# encoding: utf-8

module Nanoc::Extra

  # @deprecated Create a File instance directly and use that instead.
  class FileProxy

    instance_methods.each { |m| undef_method m unless m =~ /^__/ || m.to_s == 'object_id' }

    @@deprecation_warning_shown = false

    def initialize(path)
      @path = path
    end

    def freeze
    end

    def respond_to?(meth)
      file_instance_methods.include?(meth.to_sym)
    end

    def method_missing(sym, *args, &block)
      if !@@deprecation_warning_shown
        $stderr.puts 'WARNING: The :file attribute is deprecated and will be removed in a future version of nanoc. Instead of using this :file attribute, consider manually creating a File object when it’s needed, using the :content_filename, :meta_filename or :filename attributes.'
        @@deprecation_warning_shown = true
      end

      File.open(@path, 'r') { |io| io.__send__(sym, *args, &block) }
    end

  private

    def file_instance_methods
      @@file_instance_methods ||= Set.new(File.instance_methods.map { |m| m.to_sym })
    end

  end

end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
nanoc-3.6.2 lib/nanoc/extra/file_proxy.rb
nanoc-3.6.1 lib/nanoc/extra/file_proxy.rb
nanoc-3.6.0 lib/nanoc/extra/file_proxy.rb
nanoc-3.5.0 lib/nanoc/extra/file_proxy.rb
nanoc-3.5.0b2 lib/nanoc/extra/file_proxy.rb
nanoc-3.5.0b1 lib/nanoc/extra/file_proxy.rb
nanoc-3.4.3 lib/nanoc/extra/file_proxy.rb
nanoc-3.4.2 lib/nanoc/extra/file_proxy.rb
nanoc-3.4.1 lib/nanoc/extra/file_proxy.rb
nanoc-3.4.0 lib/nanoc/extra/file_proxy.rb
nanoc-3.3.7 lib/nanoc/extra/file_proxy.rb
nanoc-3.3.6 lib/nanoc/extra/file_proxy.rb
nanoc-3.3.5 lib/nanoc/extra/file_proxy.rb
nanoc-3.3.4 lib/nanoc/extra/file_proxy.rb
nanoc-3.3.3 lib/nanoc/extra/file_proxy.rb
nanoc-3.3.2 lib/nanoc/extra/file_proxy.rb
nanoc-3.3.1 lib/nanoc/extra/file_proxy.rb
nanoc-3.3.0 lib/nanoc/extra/file_proxy.rb