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

#descriptionObject



33
34
35
# File 'lib/entitlements/data/groups/calculated/yaml.rb', line 33

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

#membersObject



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

def members
  @members ||= begin
    Entitlements.logger.debug "Calculating members from #{filename}"
    members_from_rules(rules)
  end
end

#modifiersObject



66
67
68
# File 'lib/entitlements/data/groups/calculated/yaml.rb', line 66

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

#schema_versionObject



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

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