Sha256: c6b744d1f6b0c0bdce7188db91cb3cc8b89ca3c8224dcf1c57ed4c480ef0a8d2

Contents?: true

Size: 417 Bytes

Versions: 10

Compression:

Stored size: 417 Bytes

Contents

# frozen_string_literal: true

class HttpJsonModel
  attr_reader :json

  class << self
    def parse(attribute, path: [])
      keys = (path + [attribute]).map(&:to_s)

      Sinclair.build(self) do
        add_method(attribute) do
          keys.inject(hash) { |h, key| h[key] }
        end
      end
    end
  end

  def initialize(json)
    @json = json
  end

  def hash
    @hash ||= JSON.parse(json)
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
sinclair-2.1.1 spec/support/models/http_json_model.rb
sinclair-2.1.0 spec/support/models/http_json_model.rb
sinclair-2.0.1 spec/support/models/http_json_model.rb
sinclair-2.0.0 spec/support/models/http_json_model.rb
sinclair-1.16.3 spec/support/models/http_json_model.rb
sinclair-1.16.2 spec/support/models/http_json_model.rb
sinclair-1.16.1 spec/support/models/http_json_model.rb
sinclair-1.16.0 spec/support/models/http_json_model.rb
sinclair-1.15.0 spec/support/models/http_json_model.rb
sinclair-1.14.2 spec/support/models/http_json_model.rb