Sha256: fbede0ee01c808fef0372ef98d0a836d30df5e9022d43c5ad3272016d43a12a2

Contents?: true

Size: 614 Bytes

Versions: 2

Compression:

Stored size: 614 Bytes

Contents

require "writer/overwrite_prevention"

module Writer
  class FileCreator
    class << self
      attr_accessor :name, :content

      def create!(name, content)
        @name = OverwritePrevention.adjust(name)
        @content = content

        create_file
        return file
      end

      private
      def create_file
        File.open(name, 'w') do |f|
          f.puts content || template
        end
      end

      def template
        if Writer.template_path
          File.open(Writer.template_path).read
        end
      end

      def file
        File.open(name, 'r')
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
writer-0.1.0 lib/writer/file_creator.rb
writer-0.0.4 lib/writer/file_creator.rb