Sha256: e5be6fb40d13527295ce1e832a3fa7521a61d9be34c5b912e7f1e98ed84022b7

Contents?: true

Size: 1.76 KB

Versions: 5

Compression:

Stored size: 1.76 KB

Contents

module Inforouter
  class AccessList < Record
    # The <tt>Inforouter::AccessListDomainMembersItem</tt>.
    attr_accessor :domain_members
    # Array of <tt>Inforouter::AccessListUserGroupItem</tt>s.
    attr_accessor :user_groups
    # Array of <tt>Inforouter::AccessListUserItem</tt>s.
    attr_accessor :users

    def initialize(params = {})
      params = {
        user_groups: [],
        users: []
      }.merge(params)
      super params
    end

    # The AccessList XML fragment should be structures as
    #
    # <AccessList>
    #   <DomainMembers Right="2"/>
    #   <UserGroup Domain="" GroupName="Authors" Right="4"/>
    #   <UserGroup Domain="" GroupName="Developers" Right="5"/>
    #   <UserGroup Domain="ProjectX" GroupName="Architect" Right="6"/>
    #   <User Domain="ProjectX" UserName="JoeD" Right="4"/>
    #   <User Domain="ProjectX" UserName="JaneC" Right="6"/>
    #   <User Domain="" UserName="SuzanP" Right="6"/>
    # </AccessList>
    #
    # The Right Value can be
    #
    # 0 (No Access)
    # 1 (List)
    # 2 (Read)
    # 3 (Add)
    # 4 (Add & Read)
    # 5 (Change)
    # 6 (Full Control)
    #
    # @return [String]
    def to_xml
      builder = Nokogiri::XML::Builder.new do |xml|
        xml.AccessList do
          xml.DomainMembers(Right: domain_members.right) if domain_members
          user_groups.each do |user_group|
            xml.UserGroup(
              Domain: user_group.domain,
              GroupName: user_group.name,
              Right: user_group.right
            )
          end
          users.each do |user|
            xml.User(
              Domain: user.domain,
              UserName: user.name,
              Right: user.right
            )
          end
        end
      end
      builder.doc.root.to_s
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
inforouter-0.3.0 lib/inforouter/access_list.rb
inforouter-0.2.9 lib/inforouter/access_list.rb
inforouter-0.2.8 lib/inforouter/access_list.rb
inforouter-0.2.7 lib/inforouter/access_list.rb
inforouter-0.2.6 lib/inforouter/access_list.rb