Sha256: 05457122f5acb03bd4b32cffce729134ddfaba7f77271391fa1ff9ed0bc49b1c

Contents?: true

Size: 776 Bytes

Versions: 18

Compression:

Stored size: 776 Bytes

Contents

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

    def self.of(obj)
      # :nocov:
      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
      # :nocov:
    end

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

    def to_json(*_args)
      @json
    end

    def to_s
      @json
    end

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

    def [](key)
      # :nocov:
      to_h[key]
      # :nocov:
    end

    undef_method :as_json
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
jsonapi-resources-0.10.7 lib/jsonapi/compiled_json.rb
jsonapi-resources-0.10.6 lib/jsonapi/compiled_json.rb
jsonapi-resources-0.10.5 lib/jsonapi/compiled_json.rb
jsonapi-resources-0.10.4 lib/jsonapi/compiled_json.rb
jsonapi-resources-0.10.3 lib/jsonapi/compiled_json.rb
jsonapi-resources-0.10.2 lib/jsonapi/compiled_json.rb
jsonapi-resources-0.10.1 lib/jsonapi/compiled_json.rb
jsonapi-resources-0.10.0 lib/jsonapi/compiled_json.rb
jsonapi-resources-0.10.0.beta9 lib/jsonapi/compiled_json.rb
jsonapi-resources-0.10.0.beta8 lib/jsonapi/compiled_json.rb
jsonapi-resources-0.10.0.beta7 lib/jsonapi/compiled_json.rb
jsonapi-resources-0.10.0.beta6 lib/jsonapi/compiled_json.rb
jsonapi-resources-0.10.0.beta5 lib/jsonapi/compiled_json.rb
jsonapi-resources-0.10.0.beta4 lib/jsonapi/compiled_json.rb
jsonapi-resources-0.10.0.beta3 lib/jsonapi/compiled_json.rb
jsonapi-resources-0.10.0.beta2.1 lib/jsonapi/compiled_json.rb
jsonapi-resources-0.10.0.beta2 lib/jsonapi/compiled_json.rb
jsonapi-resources-0.10.0.beta1 lib/jsonapi/compiled_json.rb