Class: RosettAi::Thor::Tasks::Content

Inherits:
Thor
  • Object
show all
Defined in:
lib/rosett_ai/thor/tasks/content.rb

Overview

Thor task for premium content pack management.

Content packs are signed tarballs of YAML files downloaded from the NeatNerds content server. License tier is checked before download — software functionality is never restricted.

Instance Method Summary collapse

Instance Method Details

#install(pack_name) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/rosett_ai/thor/tasks/content.rb', line 56

def install(pack_name)
  result = validate_license!
  tier = result[:tier]

  client = build_client
  catalog = client.catalog(tier: tier.name.to_s)
  pack_info = catalog&.find { |entry| entry['name'] == pack_name }

  raise ::Thor::Error, t('install.not_found', name: pack_name) unless pack_info

  required_tier = RosettAi::Licensing::Tier.new(pack_info['tier_required'])
  unless tier.entitled_to?(required_tier)
    raise ::Thor::Error, t('install.tier_required', name: pack_name, required: required_tier,
                                                    current: tier)
  end

  download_and_install(client, pack_name, pack_info['version'])
rescue RosettAi::ContentError => e
  raise ::Thor::Error, e.message
end

#listObject



35
36
37
38
39
40
41
# File 'lib/rosett_ai/thor/tasks/content.rb', line 35

def list
  if options[:available]
    list_available
  else
    list_installed
  end
end

#updateObject



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/rosett_ai/thor/tasks/content.rb', line 88

def update
  validate_license!
  registry = RosettAi::Content::PackRegistry.new
  packs = registry.installed

  if packs.empty?
    puts Rainbow(t('list.no_packs')).yellow
    return
  end

  client = build_client
  packs.each do |manifest|
    puts t('update.checking', name: manifest.name)
    download_and_install(client, manifest.name, manifest.version)
  end
  puts Rainbow(t('update.success')).green
rescue RosettAi::ContentError => e
  puts Rainbow(t('update.offline')).yellow
  puts Rainbow(e.message).red
end