Class: Entitlements::Data::Groups::Calculated::Ruby

Inherits:
Base
  • Object
show all
Includes:
Contracts::Core
Defined in:
lib/entitlements.rb,
lib/entitlements/data/groups/calculated/ruby.rb

Constant Summary collapse

C =
::Contracts

Constants inherited from Base

Base::ALIAS_METHODS, Base::MAX_MODIFIER_ITERATIONS, Base::MODIFIERS

Instance Attribute Summary

Attributes inherited from Base

#filename, #filters, #metadata

Instance Method Summary collapse

Methods included from Contracts::Core

common, extended, included

Methods inherited from Base

#fatal_message, #filtered_members, #initialize, #modified_filtered_members, #modified_members, #modifiers

Constructor Details

This class inherits a constructor from Entitlements::Data::Groups::Calculated::Base

Instance Method Details

#descriptionObject



54
55
56
57
58
# File 'lib/entitlements/data/groups/calculated/ruby.rb', line 54

def description
  result = rule_obj.description
  return result if result.is_a?(String)
  raise "Expected String from #{ruby_class_name}.description, got #{result.class}!"
end

#membersObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/entitlements/data/groups/calculated/ruby.rb', line 18

def members
  @members ||= begin
    Entitlements.logger.debug "Calculating members from #{filename}"
    result = rule_obj.members

    # Since this is user-written code not subject to contracts, do some basic
    # format checking of the result, and standardize the output.
    unless result.is_a?(Set)
      raise "Expected Set[String|Entitlements::Models::Person] from #{ruby_class_name}.members, got #{result.class}!"
    end

    cleaned_set = result.map do |item|
      if item.is_a?(String)
        begin
          Entitlements.cache[:people_obj].read.fetch(item)
        rescue KeyError => exc
          raise_rule_exception(exc)
        end
      elsif item.is_a?(Entitlements::Models::Person)
        item
      else
        raise "In #{ruby_class_name}.members, expected String or Person but got #{item.inspect}"
      end
    end

    # All good, return the result.
    Set.new(cleaned_set)
  end
end