Class: Matterhorn::Acl

Inherits:
Object
  • Object
show all
Defined in:
lib/matterhorn/acl.rb

Overview

<?xml version=“1.0” encoding=“UTF-8” standalone=“yes”?> <acl xmlns=“org.opencastproject.security”>

<ace>
  <role>admin</role>
  <action>delete</action>
  <allow>true</allow>
</ace>

</acl>

Defined Under Namespace

Classes: Ace

Constant Summary collapse

NS =

————————————————————————– const definitions —

{
  'xmlns' => "http://org.opencastproject.security",
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml = nil) ⇒ Acl

—————————————————————————– initialization —



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/matterhorn/acl.rb', line 45

def initialize(xml = nil)
  if !xml.nil?
    doc = Nokogiri::XML(xml)
    @aces = []
    doc.xpath("/xmlns:acl/xmlns:ace").each do |ace_elem|
      ace = Ace.new
      ace.role   = ace_elem.at_xpath("xmlns:role").content
      ace.action = ace_elem.at_xpath("xmlns:action").content
      ace.allow  = ace_elem.at_xpath("xmlns:allow").content
      @aces << ace
    end
  else
    @aces = []
  end
end

Instance Attribute Details

#acesObject

Returns the value of attribute aces.



18
19
20
# File 'lib/matterhorn/acl.rb', line 18

def aces
  @aces
end

Instance Method Details

#inspectObject

———————————————————————————— helpers —



88
89
90
# File 'lib/matterhorn/acl.rb', line 88

def inspect
  to_xml.to_s
end

#save(file) ⇒ Object

———————————————————————————– methodes —



64
65
66
67
68
# File 'lib/matterhorn/acl.rb', line 64

def save(file)
  File.open(file, 'w') do |file|
    file.write(to_xml)
  end
end

#to_xmlObject



71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/matterhorn/acl.rb', line 71

def to_xml
  Nokogiri::XML::Builder.new do |xml|
    xml.acl(NS) do
      @aces.each do |ace|
        xml.ace do 
          xml.role(ace.role)
          xml.action(ace.action)
          xml.allow(ace.allow)
        end
      end
    end
  end.doc.to_xml
end