Class: ReactOnRailsPro::LicenseValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/react_on_rails_pro/license_validator.rb

Constant Summary collapse

GRACE_PERIOD_SECONDS =

Grace period: 1 month (in seconds)

30 * 24 * 60 * 60

Class Method Summary collapse

Class Method Details

.evaluation?Boolean

Checks if the current license is an evaluation/free license

Returns:

  • (Boolean)

    true if plan is not “paid”



49
50
51
52
53
# File 'lib/react_on_rails_pro/license_validator.rb', line 49

def evaluation?
  data = validated_license_data!
  plan = data["plan"].to_s
  plan != "paid" && !plan.start_with?("paid_")
end

.grace_days_remainingInteger?

Returns remaining grace period days if license is expired but in grace period

Returns:

  • (Integer, nil)

    Number of days remaining, or nil if not in grace period



57
58
59
60
61
62
63
# File 'lib/react_on_rails_pro/license_validator.rb', line 57

def grace_days_remaining
  # Ensure license is validated and cached
  validated_license_data!

  # Return cached grace days (nil if not in grace period)
  @grace_days_remaining
end

.reset!Object



42
43
44
45
# File 'lib/react_on_rails_pro/license_validator.rb', line 42

def reset!
  remove_instance_variable(:@license_data) if defined?(@license_data)
  remove_instance_variable(:@grace_days_remaining) if defined?(@grace_days_remaining)
end

.validated_license_data!Hash

Validates the license and returns the license data Caches the result after first validation

Returns:

  • (Hash)

    The license data

Raises:



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/react_on_rails_pro/license_validator.rb', line 15

def validated_license_data!
  return @license_data if defined?(@license_data)

  begin
    # Load and decode license (but don't cache yet)
    license_data = load_and_decode_license

    # Validate the license (raises if invalid, returns grace_days)
    grace_days = validate_license_data(license_data)

    # Validation passed - now cache both data and grace days
    @license_data = license_data
    @grace_days_remaining = grace_days

    @license_data
  rescue JWT::DecodeError => e
    error = "Invalid license signature: #{e.message}. " \
            "Your license file may be corrupted. " \
            "Get a FREE evaluation license at https://shakacode.com/react-on-rails-pro"
    handle_invalid_license(error)
  rescue StandardError => e
    error = "License validation error: #{e.message}. " \
            "Get a FREE evaluation license at https://shakacode.com/react-on-rails-pro"
    handle_invalid_license(error)
  end
end