Sha256: b65fe783fd01763909cc5084f5698c1822049016d8c1b251e08ff09a06bd80e8

Contents?: true

Size: 953 Bytes

Versions: 2

Compression:

Stored size: 953 Bytes

Contents

# h2. lib/imw/files/json.rb -- describes json files
#
# == About
#
# A class for working with JSON files.
#
# Author::    (Philip flip Kromer, Dhruv Bansal) for Infinite Monkeywrench Project (mailto:coders@infochimps.org)
# Copyright:: Copyright (c) 2008 infochimps.org
# License::   GPL 3.0
# Website::   http://infinitemonkeywrench.org/
#
# puts "#{File.basename(__FILE__)}: Yet another clever comment." # at bottobm

require 'json'
require 'imw/files/text'

module IMW
  module Files

    class Json < IMW::Files::Text

      def initialize uri, mode='r', options = {}
        super uri, mode
      end

      # Return the contents of this JSON file.
      #
      # FIXME what to do if a block is passed in?
      def load &block
        JSON.parse File.new(@path).read
      end

      # Dump +data+ to this file as JSON.
      def dump data
        super data.to_json
      end
    end
    FILE_REGEXPS << [/\.json$/, IMW::Files::Json]
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
imw-0.1.1 lib/imw/files/json.rb
imw-0.1.0 lib/imw/files/json.rb