Sha256: 42d1d2b9489987c8bc009f92d14ca2915674101183f12e9de11d16da6fbb23de

Contents?: true

Size: 642 Bytes

Versions: 17

Compression:

Stored size: 642 Bytes

Contents

module JSONAPI
  class CompiledJson
    def self.compile(h)
      new(JSON.generate(h), h)
    end

    def self.of(obj)
      case obj
        when NilClass then nil
        when CompiledJson then obj
        when String then CompiledJson.new(obj)
        when Hash then CompiledJson.compile(obj)
        else raise "Can't figure out how to turn #{obj.inspect} into CompiledJson"
      end
    end

    def initialize(json, h = nil)
      @json = json
      @h = h
    end

    def to_json(*args)
      @json
    end

    def to_s
      @json
    end

    def to_h
      @h ||= JSON.parse(@json)
    end

    undef_method :as_json
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
jsonapi-resources-0.9.12 lib/jsonapi/compiled_json.rb
jsonapi-resources-0.9.11 lib/jsonapi/compiled_json.rb
jsonapi-resources-0.9.10 lib/jsonapi/compiled_json.rb
jsonapi-resources-0.9.9 lib/jsonapi/compiled_json.rb
jsonapi-resources-0.9.8 lib/jsonapi/compiled_json.rb
jsonapi-resources-0.9.7 lib/jsonapi/compiled_json.rb
jsonapi-resources-0.9.6 lib/jsonapi/compiled_json.rb
jsonapi-resources-0.9.5 lib/jsonapi/compiled_json.rb
jsonapi-resources-0.9.4 lib/jsonapi/compiled_json.rb
jsonapi-resources-0.9.3 lib/jsonapi/compiled_json.rb
jsonapi-resources-0.9.2 lib/jsonapi/compiled_json.rb
jsonapi-resources-0.9.1.beta2 lib/jsonapi/compiled_json.rb
jsonapi-resources-0.9.1.beta1 lib/jsonapi/compiled_json.rb
jsonapi-resources-0.9.0 lib/jsonapi/compiled_json.rb
jsonapi-resources-0.9.0.beta3 lib/jsonapi/compiled_json.rb
jsonapi-resources-0.9.0.beta2 lib/jsonapi/compiled_json.rb
jsonapi-resources-0.9.0.beta1 lib/jsonapi/compiled_json.rb