Sha256: a9ee859cac278dcabd9ae4c1ed5f7850bb0cd6602e4a8a9f4308802858ecebde

Contents?: true

Size: 1.27 KB

Versions: 3

Compression:

Stored size: 1.27 KB

Contents

require_relative 'resource'

module Contentful
  module Management
    # Resource class for Space Membership.
    class SpaceMembership
      include Contentful::Management::Resource
      include Contentful::Management::Resource::SystemProperties
      include Contentful::Management::Resource::Refresher

      property :admin, :boolean
      property :roles, :array
      property :user, Link

      # Returns the list of roles for this membership.
      def roles
        (properties[:roles] || []).map { |r| r.is_a?(Link) ? r : Link.new(r, nil, client) }
      end

      # @private
      def self.clean_roles(roles)
        roles.map { |r| r.is_a?(Link) ? r.raw_object : r }
      end

      # @private
      def self.create_attributes(_client, attributes)
        {
          'admin' => attributes['admin'] || attributes.fetch(:admin),
          'roles' => clean_roles(attributes['roles'] || attributes.fetch(:roles)),
          'email' => attributes['email'] || attributes.fetch(:email)
        }
      end

      # @private
      def query_attributes(attributes)
        {
          'admin' => attributes['admin'] || attributes[:admin],
          'roles' => self.class.clean_roles(attributes['roles'] || attributes[:roles])
        }.reject { |_k, v| v.nil? }
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
contentful-management-1.10.1 lib/contentful/management/space_membership.rb
contentful-management-1.10.0 lib/contentful/management/space_membership.rb
contentful-management-1.9.0 lib/contentful/management/space_membership.rb