<commit_before>require 'sinatra'
require 'securerandom'
require 'redis-objects'
require 'virtus'

Redis.current = Redis.new(:host => '127.0.0.1', :port => 6379)

class NameSpace
  include Virtus.model
  attr_accessor :name
  def initialize(name = nil)
    @name = name.id
  end
  def attach(hashpoint)
    Redis.current.sadd(name, hashpoint.id)
  end
  def attached
    Redis.current.smembers(name)
  end
end

class Name
  include Virtus.model
  attr_accessor :on_store
  def initialize(attributes = {})
    super
    @on_store = Redis::Value.new(id, marshal: true)
  end
  attribute :id, String, default: lambda {|instance, attribute| "#{instance.class.name.downcase}:#{attribute.name}:#{[*('A'..'Z')].sample(8).join}"}
  def save
    on_store.value = attributes
  end
end

class HashPoint
  include Virtus.model
  include Redis::Objects
  attribute :id, String, default: proc { "hpoint:#{SecureRandom.hex}" }
end

post '/h/new' do
  hash = HashPoint.new
  status 303
  headers 'Location' => "/h/#{hash.id}"
end

get '/h/:hash' do |hash|
  "#{Resolver.name_from(hash)} is name"
end

module Resolver
  def self.name_from(hpoint)
    Redis.current.get("_hpoint:#{hpoint.id}")
  end
end<commit_msg>cant inherit from value with virtus easily, so just talking to store inline<commit_after>require 'sinatra'
require 'securerandom'
require 'redis-objects'
require 'virtus'

Redis.current = Redis.new(:host => '127.0.0.1', :port => 6379)

class NameSpace
  include Virtus.model
  attr_accessor :name
  def initialize(name = nil)
    @name = name.id
  end
  def attach(hashpoint)
    Redis.current.sadd(name, hashpoint.id)
  end
  def attached
    Redis.current.smembers(name)
  end
end

class Name
  include Virtus.model
  include Redis::Objects
  attribute :id, String, default: lambda {|instance, attribute| "#{instance.class.name.downcase}:#{attribute.name}:#{[*('A'..'Z')].sample(8).join}"}
  def save
    redis.set(id, attributes)
  end
end

class HashPoint
  include Virtus.model
  include Redis::Objects
  attribute :id, String, default: proc { "hpoint:#{SecureRandom.hex}" }
end

post '/h/new' do
  hash = HashPoint.new
  status 303
  headers 'Location' => "/h/#{hash.id}"
end

get '/h/:hash' do |hash|
  "#{Resolver.name_from(hash)} is name"
end

module Resolver
  def self.name_from(hpoint)
    Redis.current.get("_hpoint:#{hpoint.id}")
  end
end
{'fraction_non_alphanumeric': 0.14133673903788846, 'fraction_numerical': 0.011919965942954448, 'mean_word_length': 4.108695652173913, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '850535', 'n_tokens_mistral': 866, 'n_tokens_neox': 850, 'n_words': 207}