Class: Clacky::Identity
- Inherits:
-
Object
- Object
- Clacky::Identity
- 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
-
#bound_at ⇒ Object
readonly
Returns the value of attribute bound_at.
-
#device_token ⇒ Object
readonly
Returns the value of attribute device_token.
-
#user_id ⇒ Object
readonly
Returns the value of attribute user_id.
Class Method Summary collapse
Instance Method Summary collapse
-
#bind!(device_token:, user_id:) ⇒ Object
Persist a fresh binding from a device-authorization approval.
-
#bound? ⇒ Boolean
True when this device has a device token bound to a platform account.
- #clear! ⇒ Object
-
#initialize(attrs = {}) ⇒ Identity
constructor
A new instance of Identity.
- #save ⇒ Object
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_at ⇒ Object (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_token ⇒ Object (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_id ⇒ Object (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
.load ⇒ Object
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.
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 |
#save ⇒ Object
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 |