Class: JGrouper::Stem
- Inherits:
-
Object
- Object
- JGrouper::Stem
- Defined in:
- lib/jgrouper/stem.rb
Overview
Class Method Summary collapse
-
.find(name) {|stem| ... } ⇒ Object
Find Grouper stem by name.
-
.root {|stem| ... } ⇒ Object
Find Grouper root stem.
Instance Method Summary collapse
- #grant(subject, privilege) ⇒ Object
-
#groups ⇒ Object
Yield child groups.
-
#initialize(obj = nil) {|_self| ... } ⇒ Stem
constructor
A new instance of Stem.
-
#method_missing(meth, *args, &block) ⇒ Object
For passing methods on to Grouper Stem object.
- #revoke(subject, privilege) ⇒ Object
-
#root? ⇒ Boolean
Is this the root stem?.
-
#stems ⇒ Object
Yield child stems.
- #to_hash ⇒ Object
- #to_json ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(obj = nil) {|_self| ... } ⇒ Stem
Returns a new instance of Stem.
16 17 18 19 20 |
# File 'lib/jgrouper/stem.rb', line 16 def initialize( obj = nil ) @obj = obj yield self if block_given? self end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
For passing methods on to Grouper Stem object.
55 56 57 58 59 60 61 62 63 |
# File 'lib/jgrouper/stem.rb', line 55 def method_missing(meth, *args, &block) super if @obj.nil? begin block.call @obj.send(meth, *args) if block @obj.send(meth, *args) rescue NoMethodError super end end |
Class Method Details
.find(name) {|stem| ... } ⇒ Object
Find Grouper stem by name. Returns JGrouper::Stem
or nil
.
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/jgrouper/stem.rb', line 25 def self.find(name) begin obj = JStemFinder.find_by_name JGrouper.start_root_session, name, false rescue => e warn "JGrouper::Group.find(#{name}) => #{e}" end return nil if obj.nil? stem = self.new obj yield stem if block_given? stem end |
.root {|stem| ... } ⇒ Object
Find Grouper root stem. Returns JGrouper::Stem
or nil
.
72 73 74 75 76 77 78 |
# File 'lib/jgrouper/stem.rb', line 72 def self.root obj = JStemFinder.find_root_stem JGrouper.start_root_session return nil if obj.nil? stem = self.new obj yield stem if block_given? stem end |
Instance Method Details
#grant(subject, privilege) ⇒ Object
37 38 39 |
# File 'lib/jgrouper/stem.rb', line 37 def grant(subject, privilege) @obj.grantPriv subject.to_grouper, privilege.to_grouper, false end |
#groups ⇒ Object
Yield child groups.
44 45 46 47 48 49 50 |
# File 'lib/jgrouper/stem.rb', line 44 def groups @obj.child_groups.collect do |child| g = JGrouper::Group.new child yield g if block_given? g end end |
#revoke(subject, privilege) ⇒ Object
65 66 67 |
# File 'lib/jgrouper/stem.rb', line 65 def revoke(subject, privilege) @obj.revokePriv subject.to_grouper, privilege.to_grouper, false end |
#root? ⇒ Boolean
Is this the root stem?
83 84 85 |
# File 'lib/jgrouper/stem.rb', line 83 def root? name.empty? end |
#stems ⇒ Object
Yield child stems.
90 91 92 93 94 95 96 |
# File 'lib/jgrouper/stem.rb', line 90 def stems @obj.child_stems.collect do |child| s = self.class.new child yield s if block_given? s end end |
#to_hash ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/jgrouper/stem.rb', line 98 def to_hash h = { kind: 'stem', uuid: @obj.get_uuid, name: @obj.get_name, display_name: @obj.get_display_name, extension: @obj.get_extension, display_extension: @obj.get_display_extension, create_subject: JGrouper::Subject.new( @obj.get_create_subject ).to_hash, create_time: Time.at( @obj.get_create_time_long / 1000 ).to_datetime.rfc3339 } h[:description] = @obj.get_description unless @obj.get_description.empty? unless root? parent = @obj.get_parent_stem h[:parent] = { name: parent.get_name, uuid: parent.get_uuid } end begin h[:modify_subject] = JGrouper::Subject.new( @obj.get_modify_subject ).to_hash h[:modify_time] = Time.at( @obj.get_modify_time_long / 1000 ).to_datetime.rfc3339 rescue end h end |
#to_json ⇒ Object
125 126 127 |
# File 'lib/jgrouper/stem.rb', line 125 def to_json to_hash.to_json end |
#to_s ⇒ Object
129 130 131 132 |
# File 'lib/jgrouper/stem.rb', line 129 def to_s return nil if @obj.nil? %w( name display_name uuid ).collect { |k| "#{k}=#{ self.send(k) }" }.to_csv.chomp end |