Class: Clacky::Identity

Inherits:
Object
  • Object
show all
Defined in:
lib/clacky/identity.rb

Overview

Identity stores the client's platform-account binding, separate from BrandConfig (white-label / license). It holds the long-lived device token issued by the RFC 8628 device-authorization flow, which proves creator identity when publishing extensions to the marketplace.

~/.clacky/identity.yml structure:

device_token: "clacky-dt-..."
user_id: 42
bound_at: "2026-07-05T00:00:00Z"

Constant Summary collapse

CONFIG_DIR =
File.join(Dir.home, ".clacky")
IDENTITY_FILE =
File.join(CONFIG_DIR, "identity.yml")

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Identity

Returns a new instance of Identity.



22
23
24
25
26
# File 'lib/clacky/identity.rb', line 22

def initialize(attrs = {})
  @device_token = attrs["device_token"]
  @user_id      = attrs["user_id"]
  @bound_at     = attrs["bound_at"]
end

Instance Attribute Details

#bound_atObject (readonly)

Returns the value of attribute bound_at.



20
21
22
# File 'lib/clacky/identity.rb', line 20

def bound_at
  @bound_at
end

#device_tokenObject (readonly)

Returns the value of attribute device_token.



20
21
22
# File 'lib/clacky/identity.rb', line 20

def device_token
  @device_token
end

#user_idObject (readonly)

Returns the value of attribute user_id.



20
21
22
# File 'lib/clacky/identity.rb', line 20

def user_id
  @user_id
end

Class Method Details

.loadObject



28
29
30
31
32
33
# File 'lib/clacky/identity.rb', line 28

def self.load
  data = File.exist?(IDENTITY_FILE) ? (YAML.safe_load(File.read(IDENTITY_FILE)) || {}) : {}
  new(data)
rescue StandardError
  new({})
end

Instance Method Details

#bind!(device_token:, user_id:) ⇒ Object

Persist a fresh binding from a device-authorization approval.



41
42
43
44
45
46
47
# File 'lib/clacky/identity.rb', line 41

def bind!(device_token:, user_id:)
  @device_token = device_token
  @user_id      = user_id
  @bound_at     = Time.now.utc.iso8601
  save
  self
end

#bound?Boolean

True when this device has a device token bound to a platform account.

Returns:

  • (Boolean)


36
37
38
# File 'lib/clacky/identity.rb', line 36

def bound?
  !@device_token.nil? && !@device_token.to_s.strip.empty?
end

#clear!Object



49
50
51
52
53
54
# File 'lib/clacky/identity.rb', line 49

def clear!
  @device_token = nil
  @user_id      = nil
  @bound_at     = nil
  FileUtils.rm_f(IDENTITY_FILE)
end

#saveObject



56
57
58
59
60
# File 'lib/clacky/identity.rb', line 56

def save
  FileUtils.mkdir_p(CONFIG_DIR)
  File.write(IDENTITY_FILE, to_yaml)
  FileUtils.chmod(0o600, IDENTITY_FILE)
end