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.
-
#stems ⇒ Object
Yield child stems.
- #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 = StemFinder.find_by_name GrouperSession.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
.
68 69 70 71 72 73 74 |
# File 'lib/jgrouper/stem.rb', line 68 def self.root obj = StemFinder.find_root_stem GrouperSession.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 |
#stems ⇒ Object
Yield child stems.
79 80 81 82 83 84 85 |
# File 'lib/jgrouper/stem.rb', line 79 def stems @obj.child_stems.collect do |child| s = self.class.new child yield s if block_given? s end end |
#to_s ⇒ Object
87 88 89 90 |
# File 'lib/jgrouper/stem.rb', line 87 def to_s return nil if @obj.nil? %w( name display_name uuid ).collect { |k| "#{k}=#{ self.send(k) }" }.to_csv.chomp end |