lib/atome/kernel/universe.rb in atome-0.5.4.1.9 vs lib/atome/kernel/universe.rb in atome-0.5.5.6.4
- old
+ new
@@ -1,36 +1,40 @@
# frozen_string_literal: true
# universe method here
class Universe
- @counter=0
+ @counter = 0
@atomes = {}
- @classes = {}
@atome_list = []
@particle_list = {}
- @renderer_list = %i[html browser headless server]
- @options = {}
+ @renderer_list = %i[html browser headless server log]
@sanitizers = {}
+ @specificities = {}
+ @history = {}
+ @users = {}
+
class << self
- attr_reader :atomes, :renderer_list, :atome_list, :particle_list, :classes, :counter
+ attr_reader :atomes, :renderer_list, :atome_list, :particle_list, :classes, :counter, :atomes_specificities
def add_to_particle_list(particle = nil, type)
- instance_variable_get('@particle_list')[particle]=type
+ instance_variable_get('@particle_list')[particle] = type
end
- def add_optional_method(method_name, &method_proc)
- # this method is used to add optional methods
- # puts "3 => #{method_name}"
- instance_variable_get('@options').merge!({ method_name => method_proc })
- # puts "====> #{instance_variable_get('@options')[method_name]}"
+ def add_atomes_specificities atome_type_to_add
+ @specificities[atome_type_to_add] = {}
end
- def get_optional_method(method_name)
- # this method is used to add optional methods
- instance_variable_get('@options')[method_name]
+ def set_atomes_specificities params
+ particle_found = params[:method].to_sym
+ specificity = "#{params[:specific]}_".to_sym
+ @specificities[params[:specific]][particle_found] = specificity
end
+ def get_atomes_specificities
+ @specificities
+ end
+
def add_sanitizer_method(method_name, &method_proc)
# this method is used to add sanitizer methods
instance_variable_get('@sanitizers').merge!({ method_name => method_proc })
end
@@ -42,20 +46,39 @@
def add_to_atome_list(atome)
instance_variable_get('@atome_list').push(atome)
end
def add_to_atomes(id, atome)
- # instance_variable_get('@atomes').merge!(atome)
@atomes[id] = atome
- @counter=@counter+1
+ @counter = @counter + 1
end
def update_atome_id(id, atome, prev_id)
@atomes[id] = atome
@atomes.delete(prev_id)
end
+ def user_atomes
+ collected_id = []
+ @atomes.each do |id_found, atome_found|
+ unless atome_found.tag && atome_found.tag[:system]
+ collected_id << id_found
+ end
+ end
+ collected_id
+ end
+
+ def system_atomes
+ collected_id = []
+ @atomes.each do |id_found, atome_found|
+ if atome_found.tag && atome_found.tag[:system]
+ collected_id << id_found
+ end
+ end
+ collected_id
+ end
+
def app_identity
# each app hav its own identity, this allow to generate new user identities from th
@app_identity = 369
# the identity is define as follow : parentsCreatorID_softwareInstanceID_objetID
# in this case parents is eve so 0, Software instance number is main eVe server which is also 0,
@@ -77,31 +100,107 @@
'unknown platform'
end
platform
end
- def current_machine
+ def platform_type
+ case RUBY_PLATFORM
+ when /win/i
+ "Windows"
+ when /darwin/i
+ "macOS"
+ when /linux/i
+ "Linux"
+ when /unix/i
+ "Unix"
+ else
+ "Plate-forme inconnue"
+ end
+ end
+
+ def engine
platform = RUBY_PLATFORM.downcase
- output = `#{platform =~ /win32/ ? 'ipconfig /all' : 'ifconfig'}`
+ output = if platform == :opal
+ platform = JS.global[:navigator][:userAgent].to_s.downcase
+ platform.include?('win32') ? 'ipconfig /all' : 'ifconfig'
+ # `#{platform =~ /win32/ ? 'ipconfig /all' : 'ifconfig'}`
+ elsif platform == 'wasm32-wasi'
+ 'ifconfig'
+ elsif platform_type == :windows
+ 'ipconfig'
+ else
+ 'ifconfig'
+ end
current_machine_decision(platform, output)
# TODO: check the code above and create a sensible identity
end
+ def current_server
+ return unless RUBY_ENGINE.downcase == 'opal' # Remplacez 'atome' par la valeur correcte pour votre environnement Atome
+ JS.global[:location][:href].to_s
+
+ end
+
def current_user
@user
end
- def current_server
- `window.location.href` if RUBY_ENGINE.downcase == 'opal'
+ def add_user=(id)
+ @users[id] = true
end
- def current_user=(user)
+ def users
+ @users
+ end
+
+ def current_user=(user_id)
# TODO: create or load an existing user
# if user needs to be create the current_user will be eVe
- @user = user
+ @user = user_id
end
- def connected
- true
+ def current_machine
+ @machine
end
+
+ def current_machine=(machine_id)
+ # TODO: create or load an existing user
+ # if user needs to be create the current_user will be eVe
+ @machine = machine_id
+ end
+
+ def internet
+ if RUBY_ENGINE.downcase != :native
+ grab(:view).html.internet
+ else
+ # write code here for native
+ end
+ end
+
+ def synchronised(action_nb, pass)
+ return unless Black_matter.encode(pass) == Black_matter.password[:read][:atome]
+
+ @history[action_nb][:sync] = true
+ end
+
+ def historicize(id, operation, element, params)
+ @history[@history.length] = { id => { operation => { element => params } }, sync: false, time: Time.now }
+ end
+
+ def story(filter)
+ # temp algo awaiting db to be ready, just for POC and tests
+ return unless filter
+
+ operation = filter[:operation]
+ atome_id = filter[:id]
+ particle = filter[:particle]
+ filtered_history = []
+ @history.each do |operation_number, alteration|
+ if alteration[atome_id] && (alteration[atome_id][operation]) && (alteration[atome_id][operation][particle])
+ filtered_history << { operation: operation_number, filter[:particle] => alteration[atome_id][operation][particle], sync: alteration[:sync], time: alteration[:time] }
+ end
+ end
+ filtered_history
+ end
+
end
end