Class: JGrouper::GroupType

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

Overview

JGrouper::GroupType - Grouper Group Type

Usage

require 'jgrouper'

TODO

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of GroupType.

Yields:

  • (_self)

Yield Parameters:



15
16
17
18
19
# File 'lib/jgrouper/group_type.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 GroupType object.



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

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

.allObject

Find all group types.



24
25
26
# File 'lib/jgrouper/group_type.rb', line 24

def self.all
  JGroupTypeFinder.find_all.collect { |_| self.new _ }
end

.find(name) {|group_type| ... } ⇒ Object

Find group type by name. Returns JGrouper::GroupType or nil.

Yields:

  • (group_type)


31
32
33
34
35
36
37
38
39
40
41
# File 'lib/jgrouper/group_type.rb', line 31

def self.find(name)
  begin
    obj = JGroupTypeFinder.find name, false
  rescue => e
    warn "JGrouper::GroupType.find(#{name}) => #{e}"
  end
  return nil if obj.nil?
  group_type = self.new obj
  yield group_type if block_given?
  group_type 
end

Instance Method Details

#to_grouperObject

Return Grouper object.



59
# File 'lib/jgrouper/group_type.rb', line 59

def to_grouper; @obj; end

#to_hashObject



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/jgrouper/group_type.rb', line 61

def to_hash
  {
    kind:         'group_type',
    name:         @obj.get_name,
    uuid:         @obj.get_uuid,
    assignable:   @obj.get_is_assignable,
    internal:     @obj.get_is_internal,
    create_time:  Time.at( @obj.get_create_time / 1000 ).to_datetime.rfc3339,
    create_uuid:  @obj.get_creator_uuid,
    fields:       @obj.get_fields.collect { |f| { name: f.get_name, uuid: f.get_uuid } }
  }
end

#to_jsonObject



74
75
76
# File 'lib/jgrouper/group_type.rb', line 74

def to_json
  to_hash.to_json
end

#to_sObject



78
79
80
81
# File 'lib/jgrouper/group_type.rb', line 78

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