Sha256: 341554e1d088ef76f28446be7888a012cae62e00c668119ab364e3179f1bf6f5

Contents?: true

Size: 472 Bytes

Versions: 1

Compression:

Stored size: 472 Bytes

Contents

module Upholsterer
  class Base
    def to_hash
      Hash[json_fields.collect do |field|
        [field, public_send(field)]
      end]
    end

    def to_json(*args)
      to_hash
    end

    alias :to_h :to_hash
    alias :as_json :to_json

  private

    def json_fields
      @json_fields ||= public_methods(false).tap do |fields|
        fields.delete(:subject)
        fields.delete(:respond_to?)
        fields.delete(:method_missing)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
upholsterer-0.4.4 lib/upholsterer/json_presenter.rb