Class: JGrouper::Stem

Inherits:
Object
  • Object
show all
Defined in:
lib/jgrouper/stem.rb

Overview

JGrouper::Stem - Grouper Stem

Usage

require 'jgrouper'

root = JGrouper::Stem.root

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(obj = nil) {|_self| ... } ⇒ Stem

Returns a new instance of Stem.

Yields:

  • (_self)

Yield Parameters:



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.



47
48
49
50
51
52
53
54
55
# File 'lib/jgrouper/stem.rb', line 47

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.

Yields:

  • (stem)


25
26
27
28
29
30
31
# File 'lib/jgrouper/stem.rb', line 25

def self.find(name)
  obj = StemFinder.find_by_name GrouperSession.start_root_session, name, false
  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.

Yields:

  • (stem)


60
61
62
63
64
65
66
# File 'lib/jgrouper/stem.rb', line 60

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

#groupsObject

Yield child groups.



36
37
38
39
40
41
42
# File 'lib/jgrouper/stem.rb', line 36

def groups
  @obj.child_groups.collect do |child|
    g = JGrouper::Group.new child
    yield g if block_given?
    g
  end
end

#stemsObject

Yield child stems.



71
72
73
74
75
76
77
# File 'lib/jgrouper/stem.rb', line 71

def stems
  @obj.child_stems.collect do |child|
    s = self.new child
    yield s if block_given?
    s
  end
end

#to_sObject



79
80
81
82
# File 'lib/jgrouper/stem.rb', line 79

def to_s
  return nil if @obj.nil?
  CSV.generate_line %w( name display_name uuid ).collect { |k| "#{k}=#{ self.send(k) }" }
end