Class: Entitlements::Data::Groups::Calculated::Base

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

Direct Known Subclasses

Ruby, Text, YAML

Constant Summary collapse

C =
::Contracts
ALIAS_METHODS =
{
  "entitlements_group" => "group"
}
MAX_MODIFIER_ITERATIONS =
100
MODIFIERS =
%w[
  expiration
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename:, config: nil, options: {}) ⇒ Base

Returns a new instance of Base.



86
87
88
89
90
91
92
# File 'lib/entitlements/data/groups/calculated/base.rb', line 86

def initialize(filename:, config: nil, options: {})
  @filename = filename
  @config = config
  @options = options
  @metadata = 
  @filters = initialize_filters
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



31
32
33
# File 'lib/entitlements/data/groups/calculated/base.rb', line 31

def filename
  @filename
end

#filtersObject (readonly)

Returns the value of attribute filters.



31
32
33
# File 'lib/entitlements/data/groups/calculated/base.rb', line 31

def filters
  @filters
end

#metadataObject (readonly)

Returns the value of attribute metadata.



31
32
33
# File 'lib/entitlements/data/groups/calculated/base.rb', line 31

def 
  @metadata
end

Instance Method Details

#descriptionObject



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

def description
  # :nocov:
  raise "Must be implemented in child class"
  # :nocov:
end

#fatal_message(message) ⇒ Object

Raises:

  • (RuntimeError)


100
101
102
103
# File 'lib/entitlements/data/groups/calculated/base.rb', line 100

def fatal_message(message)
  Entitlements.logger.fatal(message)
  raise RuntimeError, message
end

#filtered_membersObject



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/entitlements/data/groups/calculated/base.rb', line 111

def filtered_members
  return :calculating if members == :calculating

  # Start with the set of all members that are calculated. For each filter that is not set
  # to the special value :all, run the filter to remove progressively more members.
  @filtered_members ||= begin
    result = members.dup
    filters.reject { |_, filter_val| filter_val == :all }.each do |filter_name, filter_val|
      filter_cfg = Entitlements::Data::Groups::Calculated.filters_index[filter_name]
      clazz = filter_cfg.fetch(:class)
      obj = clazz.new(filter: filter_val, config: filter_cfg.fetch(:config, {}))
      # If excluded_paths is set, ignore any of those excluded paths
      unless filter_cfg[:config]["excluded_paths"].nil?
        # if the filename is not in any of the excluded paths, filter it
        unless filter_cfg[:config]["excluded_paths"].any? { |excluded_path| filename.include?(excluded_path) }
          result.reject! { |member| obj.filtered?(member) }
        end
      end

      # if included_paths is set, filter only files at those included paths
      unless filter_cfg[:config]["included_paths"].nil?
        # if the filename is in any of the included paths, filter it
        if filter_cfg[:config]["included_paths"].any? { |included_path| filename.include?(included_path) }
          result.reject! { |member| obj.filtered?(member) }
        end
      end

      # if neither included_paths nor excluded_paths are set, filter normally
      if filter_cfg[:config]["included_paths"].nil? and filter_cfg[:config]["excluded_paths"].nil?
        result.reject! { |member| obj.filtered?(member) }
      end
    end
    result
  end
end

#membersObject



43
44
45
46
47
# File 'lib/entitlements/data/groups/calculated/base.rb', line 43

def members
  # :nocov:
  raise "Must be implemented in child class"
  # :nocov:
end

#modified_filtered_membersObject



164
165
166
167
# File 'lib/entitlements/data/groups/calculated/base.rb', line 164

def modified_filtered_members
  return :calculating if filtered_members == :calculating
  @modified_filtered_members ||= apply_modifiers(filtered_members)
end

#modified_membersObject



153
154
155
156
# File 'lib/entitlements/data/groups/calculated/base.rb', line 153

def modified_members
  return :calculating if members == :calculating
  @modified_members ||= apply_modifiers(members)
end

#modifiersObject



68
69
70
# File 'lib/entitlements/data/groups/calculated/base.rb', line 68

def modifiers
  {}
end