Sha256: 79fbcbe50f2881bb6ae5a246a062b07d0109850df063a65aa45bad98231ff50b

Contents?: true

Size: 786 Bytes

Versions: 10

Compression:

Stored size: 786 Bytes

Contents

module Hyperclient
  # Public: A wrapper class to easily acces the attributes in a Resource.
  #
  # Examples
  #
  #   resource.attributes['title']
  #   resource.attributes.title
  #
  class Attributes < Collection
    RESERVED_PROPERTIES = [/^_links$/, /^_embedded$/].freeze # http://tools.ietf.org/html/draft-kelly-json-hal#section-4.1

    # Public: Initializes the Attributes of a Resource.
    #
    # representation - The hash with the HAL representation of the Resource.
    #
    def initialize(representation)
      @collection = if representation.is_a?(Hash)
                      representation.delete_if { |key, _value| RESERVED_PROPERTIES.any? { |p| p.match(key) } }
                    else
                      representation
                    end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
hyperclient-2.0.0 lib/hyperclient/attributes.rb
hyperclient-1.0.1 lib/hyperclient/attributes.rb
hyperclient-0.9.3 lib/hyperclient/attributes.rb
hyperclient-0.9.1 lib/hyperclient/attributes.rb
hyperclient-0.9.0 lib/hyperclient/attributes.rb
hyperclient-0.8.6 lib/hyperclient/attributes.rb
hyperclient-0.8.5 lib/hyperclient/attributes.rb
hyperclient-0.8.4 lib/hyperclient/attributes.rb
hyperclient-0.8.3 lib/hyperclient/attributes.rb
hyperclient-0.8.2 lib/hyperclient/attributes.rb