Sha256: d3568945b72d1d60793ce730ab82f01abd44f8dc73042df680988e8d9bb8e762

Contents?: true

Size: 1.57 KB

Versions: 13

Compression:

Stored size: 1.57 KB

Contents

module GroupDocs
  module Api
    module Helpers
      module AccessRights

        include Api::Helpers::ByteFlag

        ACCESS_RIGHTS = {
          :export   => 1,
          :download => 2,
          :proof    => 4,
          :view     => 8,
        }

        private

        #
        # Converts shared link access rights array to byte flag.
        #
        # @param [Array<String, Symbol>] rights
        # @return [Integer]
        # @raise [ArgumentError] if rights is not an array
        # @raise [ArgumentError] if right is unknown
        # @api private
        #
        def convert_access_rights_to_byte(rights)
          rights.is_a?(Array) or raise ArgumentError, "Rights should be an array, received: #{rights.inspect}"
          rights = rights.map(&:to_sym)

          possible_rights = ACCESS_RIGHTS.map { |hash| hash.first }
          rights.each do |right|
            possible_rights.include?(right) or raise ArgumentError, "Unknown access right: #{rights.inspect}"
          end

          byte_from_array(rights, ACCESS_RIGHTS)
        end

        #
        # Converts byte flag to shared link access rights array.
        #
        # @param [Integer] rights
        # @return [Array<Symbol>]
        # @raise [ArgumentError] if rights is not integer
        # @api private
        #
        def convert_byte_to_access_rights(rights)
          rights.is_a?(Integer) or raise ArgumentError, "Rights should be an integer, received: #{rights.inspect}"
          array_from_byte(rights, ACCESS_RIGHTS)
        end

      end # AccessRights
    end # Helpers
  end # Api
end # GroupDocs

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
groupdocs-1.5.8 lib/groupdocs/api/helpers/access_rights_helper.rb
groupdocs-1.5.7 lib/groupdocs/api/helpers/access_rights_helper.rb
groupdocs-1.5.6 lib/groupdocs/api/helpers/access_rights_helper.rb
groupdocs-1.5.5 lib/groupdocs/api/helpers/access_rights_helper.rb
groupdocs-1.5.4 lib/groupdocs/api/helpers/access_rights_helper.rb
groupdocs-1.5.3 lib/groupdocs/api/helpers/access_rights_helper.rb
groupdocs-1.5.2 lib/groupdocs/api/helpers/access_rights_helper.rb
groupdocs-1.5.1 lib/groupdocs/api/helpers/access_rights_helper.rb
groupdocs-1.5.0 lib/groupdocs/api/helpers/access_rights_helper.rb
groupdocs-1.4.2 lib/groupdocs/api/helpers/access_rights_helper.rb
groupdocs-1.4.1 lib/groupdocs/api/helpers/access_rights_helper.rb
groupdocs-1.4.0 lib/groupdocs/api/helpers/access_rights_helper.rb
groupdocs-1.3.0 lib/groupdocs/api/helpers/access_rights_helper.rb