Class: Entitlements::Data::Groups::Calculated::YAML

Inherits:
Base
  • Object
show all
Includes:
Contracts::Core
Defined in:
lib/entitlements.rb,
lib/entitlements/data/groups/calculated/yaml.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

Constructor Details

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

Instance Method Details

#description ⇒ Object



35
36
37
# File 'lib/entitlements/data/groups/calculated/yaml.rb', line 35

def description
  parsed_data.fetch("description", "")
end

#members ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/entitlements/data/groups/calculated/yaml.rb', line 20

def members
  return @members if @members

  Entitlements.logger.debug "Calculating members from #{filename}"
  result = members_from_rules(rules)
  @members = result unless result == :calculating
  result
end

#modifiers ⇒ Object



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

def modifiers
  parsed_data.select { |k, _v| MODIFIERS.include?(k) }
end

#schema_version ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/entitlements/data/groups/calculated/yaml.rb', line 47

def schema_version
  schema_version = parsed_data.fetch("schema_version", "entitlements/v1").to_s

  namespace, version = schema_version.split("/")

  unless namespace.match?(/\A[a-zA-Z0-9]+\z/) && version.match?(/\A(v?\d+(\.\d+){0,2})\z/)
    raise "Invalid schema version format: #{schema_version} - Expected format is '<namespace>/<version>' " \
          "- Examples: entitlements/v1, entitlements/v1.2.3, entitlements/1.2.3"
  end

  # rebuild the schema version string to ensure it's in the correct format and return it
  return "#{namespace}/#{version}"
end