Class: Universe

Inherits:
Object show all
Defined in:
lib/atome/kernel/universe.rb

Overview

universe method here

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.active_toolsObject

Returns the value of attribute active_tools.



38
39
40
# File 'lib/atome/kernel/universe.rb', line 38

def active_tools
  @active_tools
end

.allow_localstorageObject

Returns the value of attribute allow_localstorage.



38
39
40
# File 'lib/atome/kernel/universe.rb', line 38

def allow_localstorage
  @allow_localstorage
end

.allow_syncObject

Returns the value of attribute allow_sync.



38
39
40
# File 'lib/atome/kernel/universe.rb', line 38

def allow_sync
  @allow_sync
end

.allow_tool_operationsObject

Returns the value of attribute allow_tool_operations.



38
39
40
# File 'lib/atome/kernel/universe.rb', line 38

def allow_tool_operations
  @allow_tool_operations
end

.applicable_atomesObject

Returns the value of attribute applicable_atomes.



38
39
40
# File 'lib/atome/kernel/universe.rb', line 38

def applicable_atomes
  @applicable_atomes
end

.atome_listObject (readonly)

Returns the value of attribute atome_list.



36
37
38
# File 'lib/atome/kernel/universe.rb', line 36

def atome_list
  @atome_list
end

.atome_presetObject

Returns the value of attribute atome_preset.



38
39
40
# File 'lib/atome/kernel/universe.rb', line 38

def atome_preset
  @atome_preset
end

.atomesObject (readonly)

Returns the value of attribute atomes.



36
37
38
# File 'lib/atome/kernel/universe.rb', line 36

def atomes
  @atomes
end

.atomes_idsObject (readonly)

Returns the value of attribute atomes_ids.



36
37
38
# File 'lib/atome/kernel/universe.rb', line 36

def atomes_ids
  @atomes_ids
end

.atomes_specificitiesObject (readonly)

Returns the value of attribute atomes_specificities.



36
37
38
# File 'lib/atome/kernel/universe.rb', line 36

def atomes_specificities
  @atomes_specificities
end

.classesObject (readonly)

Returns the value of attribute classes.



36
37
38
# File 'lib/atome/kernel/universe.rb', line 36

def classes
  @classes
end

.connectedObject

Returns the value of attribute connected.



38
39
40
# File 'lib/atome/kernel/universe.rb', line 38

def connected
  @connected
end

.counterObject (readonly)

Returns the value of attribute counter.



36
37
38
# File 'lib/atome/kernel/universe.rb', line 36

def counter
  @counter
end

.database_readyObject

Returns the value of attribute database_ready.



38
39
40
# File 'lib/atome/kernel/universe.rb', line 38

def database_ready
  @database_ready
end

.default_selection_styleObject

Returns the value of attribute default_selection_style.



38
39
40
# File 'lib/atome/kernel/universe.rb', line 38

def default_selection_style
  @default_selection_style
end

.edit_modeObject

Returns the value of attribute edit_mode.



38
39
40
# File 'lib/atome/kernel/universe.rb', line 38

def edit_mode
  @edit_mode
end

.languageObject

Returns the value of attribute language.



38
39
40
# File 'lib/atome/kernel/universe.rb', line 38

def language
  @language
end

.molecule_listObject (readonly)

Returns the value of attribute molecule_list.



36
37
38
# File 'lib/atome/kernel/universe.rb', line 36

def molecule_list
  @molecule_list
end

.particle_listObject (readonly)

Returns the value of attribute particle_list.



36
37
38
# File 'lib/atome/kernel/universe.rb', line 36

def particle_list
  @particle_list
end

.renderer_listObject (readonly)

Returns the value of attribute renderer_list.



36
37
38
# File 'lib/atome/kernel/universe.rb', line 36

def renderer_list
  @renderer_list
end

.toolsObject

Returns the value of attribute tools.



38
39
40
# File 'lib/atome/kernel/universe.rb', line 38

def tools
  @tools
end

.tools_rootObject

Returns the value of attribute tools_root.



38
39
40
# File 'lib/atome/kernel/universe.rb', line 38

def tools_root
  @tools_root
end

.translationObject

Returns the value of attribute translation.



38
39
40
# File 'lib/atome/kernel/universe.rb', line 38

def translation
  @translation
end

Class Method Details

.add_atomes_specificities(atome_type_to_add) ⇒ Object



79
80
81
# File 'lib/atome/kernel/universe.rb', line 79

def add_atomes_specificities atome_type_to_add
  @specificities[atome_type_to_add] = {}
end

.add_sanitizer_method(method_name, &method_proc) ⇒ Object



93
94
95
96
# File 'lib/atome/kernel/universe.rb', line 93

def add_sanitizer_method(method_name, &method_proc)
  # this method is used to add sanitizer methods
  @sanitizers.merge!({ method_name => method_proc })
end

.add_to_atome_list(atome) ⇒ Object



103
104
105
# File 'lib/atome/kernel/universe.rb', line 103

def add_to_atome_list(atome)
  @atome_list.push(atome)
end

.add_to_atomes(aid, atome) ⇒ Object



111
112
113
114
# File 'lib/atome/kernel/universe.rb', line 111

def add_to_atomes(aid, atome)
  @atomes[aid] = atome
  @counter = @counter + 1
end

.add_to_molecule_list(molecule) ⇒ Object



107
108
109
# File 'lib/atome/kernel/universe.rb', line 107

def add_to_molecule_list(molecule)
  @molecule_list.push(molecule)
end

.add_to_particle_list(particle = nil, type, category) ⇒ Object



74
75
76
77
# File 'lib/atome/kernel/universe.rb', line 74

def add_to_particle_list(particle = nil, type, category)
  # instance_variable_get('@particle_list')[particle] = { type: type, category: category }
  @particle_list[particle] = { type: type, category: category }
end

.add_user=(id) ⇒ Object



208
209
210
# File 'lib/atome/kernel/universe.rb', line 208

def add_user=(id)
  @users[id] = true
end

.app_identityObject



142
143
144
145
146
147
148
149
# File 'lib/atome/kernel/universe.rb', line 142

def app_identity
  # each app has its own identity, this allow to generate new user identities from the
  # unique_id = generate_unique_id_with_timestamp
  @app_identity = generate_uuid
  # 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,
  # and finally the object is 3 as this the third object created by the main server
end

.categoriesObject



70
71
72
# File 'lib/atome/kernel/universe.rb', line 70

def categories
  @categories
end

.current_machineObject



222
223
224
# File 'lib/atome/kernel/universe.rb', line 222

def current_machine
  @machine
end

.current_machine=(machine_id) ⇒ Object



226
227
228
229
230
# File 'lib/atome/kernel/universe.rb', line 226

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

.current_machine_decision(platform, output) ⇒ Object



155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/atome/kernel/universe.rb', line 155

def current_machine_decision(platform, output)
  case platform
  when /darwin/
    ::Regexp.last_match(1) if output =~ /en1.*?(([A-F0-9]{2}:){5}[A-F0-9]{2})/im
  when /win32/
    ::Regexp.last_match(1) if output =~ /Physical Address.*?(([A-F0-9]{2}-){5}[A-F0-9]{2})/im
  else
    # Cases for other platforms...
    'unknown platform'
  end
  platform
end

.current_serverObject



200
201
202
# File 'lib/atome/kernel/universe.rb', line 200

def current_server
  JS.global[:location][:href].to_s
end

.current_userObject



204
205
206
# File 'lib/atome/kernel/universe.rb', line 204

def current_user
  @user
end

.current_user=(user_id) ⇒ Object



216
217
218
219
220
# File 'lib/atome/kernel/universe.rb', line 216

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_id
end

.delete(id) ⇒ Object



151
152
153
# File 'lib/atome/kernel/universe.rb', line 151

def delete(id)
  @atomes.delete(id)
end

.delete_messages(msg_to_del) ⇒ Object



50
51
52
# File 'lib/atome/kernel/universe.rb', line 50

def delete_messages(msg_to_del)
  @messages.delete(msg_to_del)
end

.engineObject



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/atome/kernel/universe.rb', line 183

def engine
  platform = RUBY_PLATFORM.downcase
  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

.generate_uuidObject



136
137
138
139
140
# File 'lib/atome/kernel/universe.rb', line 136

def generate_uuid
  uuid = SecureRandom.uuid.gsub('-', '')
  formatted_time = Time.now.strftime("%Y%m%d%H%M%S")
  "#{uuid}#{formatted_time}"
end

.get_atomes_specificitiesObject



89
90
91
# File 'lib/atome/kernel/universe.rb', line 89

def get_atomes_specificities
  @specificities
end

.get_example(particle) ⇒ Object



66
67
68
# File 'lib/atome/kernel/universe.rb', line 66

def get_example(particle)
  @example[particle]
end

.get_help(particle) ⇒ Object



58
59
60
# File 'lib/atome/kernel/universe.rb', line 58

def get_help(particle)
  @help[particle]
end

.get_sanitizer_method(method_name) ⇒ Object



98
99
100
101
# File 'lib/atome/kernel/universe.rb', line 98

def get_sanitizer_method(method_name)
  # this method is used to add optional methods
  @sanitizers[method_name]
end

.historicize(id, operation, element, params) ⇒ Object



246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/atome/kernel/universe.rb', line 246

def historicize(id, operation, element, params)

  if @allow_sync && Universe.connected
    A.sync({ action: :historicize, data: { table: :user } })
  end

  # if @allow_localstorage && @database_ready
  if @allow_localstorage

    operation_timing = Time.now.strftime("%Y%m%d%H%M%S%3N") + @increment.to_s
    @increment += 1
    @increment = @increment % 100
    if @allow_localstorage.include? element
      JS.global[:localStorage].setItem(operation_timing, "{ #{id} => { #{operation} => { #{element} => #{params} } }, sync: false }")
      @history[@history.length] = { operation_timing => { id => { operation => { element => params } }, sync: false, time: Time.now } }
    end

  end
end

.id_to_aid(id, aid) ⇒ Object



116
117
118
# File 'lib/atome/kernel/universe.rb', line 116

def id_to_aid(id, aid)
  @atomes_ids[id] = aid
end

.internetObject



232
233
234
235
236
237
238
# File 'lib/atome/kernel/universe.rb', line 232

def internet
  if RUBY_ENGINE.downcase != :native
    grab(:view).html.internet
  else
    # write code here for native
  end
end

.messagesObject



42
43
44
# File 'lib/atome/kernel/universe.rb', line 42

def messages
  @messages
end

.platform_typeObject



168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/atome/kernel/universe.rb', line 168

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

.set_atomes_specificities(params) ⇒ Object



83
84
85
86
87
# File 'lib/atome/kernel/universe.rb', line 83

def set_atomes_specificities params
  particle_found = params[:method].to_sym
  specificity = "#{params[:specific]}_".to_sym
  @specificities[params[:specific]][particle_found] = specificity
end

.set_example(particle, &example) ⇒ Object



62
63
64
# File 'lib/atome/kernel/universe.rb', line 62

def set_example(particle, &example)
  @example[particle] = example
end

.set_help(particle, &doc) ⇒ Object



54
55
56
# File 'lib/atome/kernel/universe.rb', line 54

def set_help(particle, &doc)
  @help[particle] = doc
end

.store_messages(new_msg) ⇒ Object



46
47
48
# File 'lib/atome/kernel/universe.rb', line 46

def store_messages(new_msg)
  @messages[new_msg[:msg_nb]] = new_msg[:proc]
end

.storyObject



266
267
268
# File 'lib/atome/kernel/universe.rb', line 266

def story
  @history
end

.synchronised(action_nb, pass) ⇒ Object



240
241
242
243
244
# File 'lib/atome/kernel/universe.rb', line 240

def synchronised(action_nb, pass)
  return unless Black_matter.encode(pass) == Black_matter.password[:read][:atome]

  @history[action_nb][:sync] = true
end

.system_atomesObject



128
129
130
131
132
133
134
# File 'lib/atome/kernel/universe.rb', line 128

def system_atomes
  collected_id = []
  @atomes.each do |id_found, atome_found|
    collected_id << id_found if atome_found.tag && atome_found.tag[:system]
  end
  collected_id
end

.user_atomesObject



120
121
122
123
124
125
126
# File 'lib/atome/kernel/universe.rb', line 120

def user_atomes
  collected_id = []
  @atomes.each_value do |atome_found|
    collected_id << atome_found.id unless atome_found.tag && atome_found.tag[:system]
  end
  collected_id
end

.usersObject



212
213
214
# File 'lib/atome/kernel/universe.rb', line 212

def users
  @users
end