Class: JGrouper::Subject

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

Overview

JGrouper::Subject - Grouper Subject

Usage

require 'jgrouper'

subj = JGrouper::Subject.find id_or_identifier

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

TODO

Yields:

  • (_self)

Yield Parameters:



15
16
17
18
19
# File 'lib/jgrouper/subject.rb', line 15

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 subject object.



39
40
41
42
43
44
45
46
47
# File 'lib/jgrouper/subject.rb', line 39

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(id_or_identifier) {|subject| ... } ⇒ Object

Find Grouper subject by id-or-identifier. Returns JGrouper::Subject or nil.

Yields:

  • (subject)


24
25
26
27
28
29
30
31
32
33
34
# File 'lib/jgrouper/subject.rb', line 24

def self.find(id_or_identifier)
  begin
    subj = JSubjectFinder.find_by_id_or_identifier id_or_identifier, false
  rescue => e
    warn "JGrouper::Subject.find(#{id_or_identifier}) => #{e}"
  end
  return nil if subj.nil?
  subject = self.new subj
  yield subject if block_given?
  subject
end

Instance Method Details

#to_grouperObject



49
# File 'lib/jgrouper/subject.rb', line 49

def to_grouper; @obj; end

#to_hashObject



51
52
53
54
55
56
57
58
# File 'lib/jgrouper/subject.rb', line 51

def to_hash
  {
    kind:   'subject',
    id:     @obj.get_id,
    source: @obj.get_source_id,
    type:   @obj.get_type_name
  }
end

#to_jsonObject



60
61
62
# File 'lib/jgrouper/subject.rb', line 60

def to_json
  to_hash.to_json
end

#to_sObject



64
65
66
67
# File 'lib/jgrouper/subject.rb', line 64

def to_s
  return nil if @obj.nil?
  %w( id type_name source_id name ).collect { |k| "#{k}=#{ self.send(k) }" }.to_csv.chomp
end