Class: CommandTower::Services::ClientCompatibility::Evaluate

Inherits:
Object
  • Object
show all
Defined in:
app/services/command_tower/services/client_compatibility/evaluate.rb

Overview

Pure, deterministic client-version-compatibility decision.

Same (headers, controller/action, registry state) always produces the same complete Decision. This service MUST NOT mutate CommandTower::Current or any other request-global — it has zero side effects beyond returning its result. Any placement of recommendation metadata onto Current is transport plumbing that belongs to the workflow or boundary layer, never here.

Defined Under Namespace

Classes: Decision

Constant Summary collapse

DECISIONS =
i[compatible recommended incompatible identity_invalid].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_version_header:, platform_header:, controller_class:, action_name:, registry:) ⇒ Evaluate

Returns a new instance of Evaluate.



61
62
63
64
65
66
67
# File 'app/services/command_tower/services/client_compatibility/evaluate.rb', line 61

def initialize(app_version_header:, platform_header:, controller_class:, action_name:, registry:)
  @app_version_header = app_version_header
  @platform_header = platform_header
  @controller_class = controller_class
  @action_name = action_name.to_s
  @registry = registry
end

Class Method Details

.call(app_version_header:, platform_header:, controller_class:, action_name:, registry: CommandTower.config.registry.client_compatibility) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'app/services/command_tower/services/client_compatibility/evaluate.rb', line 51

def self.call(app_version_header:, platform_header:, controller_class:, action_name:, registry: CommandTower.config.registry.client_compatibility)
  new(
    app_version_header:,
    platform_header:,
    controller_class:,
    action_name:,
    registry:
  ).call
end

Instance Method Details

#call ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/services/command_tower/services/client_compatibility/evaluate.rb', line 69

def call
  return no_op_decision unless registry.opted_in?

  platform = normalized_platform
  version = normalized_version
  return identity_invalid_decision(platform:) if platform.nil? || version.nil?

  policy = registry.platform_policy(platform)
  return identity_invalid_decision(platform:, current_version: version) if policy.nil?

  matched = matched_entity_names
  effective_minimum, scope = effective_minimum_and_scope(policy:, platform:, matched:)

  current = Gem::Version.new(version)
  minimum = Gem::Version.new(effective_minimum)

  if current < minimum
    return incompatible_decision(
      platform:, current_version: version, effective_minimum:, scope:, matched:, policy:
    )
  end

  compatible_or_recommended_decision(
    platform:, current_version: version, effective_minimum:, matched:, policy:, current:
  )
end