atome 0.5.6.1.9 → 0.5.6.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c9f271978fff8b31e480fd6d7dd63b4714f22f658c602a2725234bdb747e29bc
4
- data.tar.gz: 7d61a71ff963c9b68b15dbbbe0a6469865d1aa82e958dca9b5cfffc4ad5ffd8c
3
+ metadata.gz: 695be1c2b746dd4a424e74ebb28ff18884fb207fb1de1bd8db9ea732b1fd7574
4
+ data.tar.gz: 943340100b85b85ebb8c1d1af89801b89204c810452cb16a860ace32b3e47190
5
5
  SHA512:
6
- metadata.gz: c9b78286af7e45b82ab00792ab2a4a11ec008c2fee10cd110666cd38a9ae11c1b5d8e6bc520854f3e033018a05046fb4d92296da7360522d4d9ef4a1ec0de1ea
7
- data.tar.gz: 365f481ee7933540065b259b4ea5d3b55515dc0b2b96f0dfc57231c55c927b54e307a41a551b208c8825e81dfe535b9be006b2dd05330ecfa78be32678d31c02
6
+ metadata.gz: 3cb8f32ad5373a51222e70c87261e5c8cc0d05a0038d2087a5e433aeacd08cdeacfb43fc692ac489d18d82a6471ce4bdced8e647cd1e10e97664bcf6c6bbdf4d
7
+ data.tar.gz: bf36e8c816ebbd99fc36aee7d4dd94bbb324e1b5caf1017731e598e1423a0524ab55b0e13b060c8d6d67ab0c6cdaa0368b0d93e6d9e9479257bfec890788e6b0
@@ -10,10 +10,12 @@ new({ particle: :message, category: :communication, type: :hash }) do |params, b
10
10
  params = { data: params } unless params.instance_of? Hash
11
11
  params[:user] = 'dfghg4df5gdfgh654'
12
12
  params[:pass] = 'gfhkzrhgzr4h98948'
13
- instance_variable_set('@message_code', {}) unless instance_variable_get('@message_code')
14
- store_proc= instance_variable_get('@message_code')
15
- mmessage_id= "msg_#{store_proc.length}"
16
- store_proc[mmessage_id]=bloc
13
+ # instance_variable_set('@message_code', {}) unless instance_variable_get('@message_code')
14
+ # store_proc= instance_variable_get('@message_code')
15
+ message_id= "msg_#{Universe.messages.length}"
16
+ params[:message_id]=message_id
17
+ # store_proc[mmessage_id]=bloc
18
+ Universe.store_messages({msg_nb:message_id, proc: bloc })
17
19
  html.send_message(params)
18
20
 
19
21
  end
@@ -141,7 +141,9 @@ end
141
141
  def atome_genesis
142
142
  atome_infos
143
143
  A.server({ address: 'localhost:9292', type: 'ws' })
144
- A.init_websocket
144
+ A.init_websocket do |msg|
145
+ puts "-3 #{msg}"
146
+ end
145
147
  end
146
148
 
147
149
  def init_database # this method is call from JS (atome/communication)
@@ -149,6 +151,7 @@ def init_database # this method is call from JS (atome/communication)
149
151
  particles = Universe.particle_list
150
152
  categories = Universe.categories
151
153
  atomes = Universe.atomes
154
+ # puts "we are here!!"
152
155
  # particles.each do |particle, value|
153
156
  # value[:category] = :undefined if value[:category].nil?
154
157
  # A.message({ action: :init_db, particle: particle, type: value[:type], category: value[:category] })
@@ -158,6 +161,10 @@ end
158
161
  def user_login
159
162
  user = Universe.current_user
160
163
  pass = Black_matter.password
161
- message({ action: :login, value: user })
162
- message({ action: :pass, value: pass })
164
+ message({ action: :login, value: user }) do |msg|
165
+ puts "-2 #{msg}"
166
+ end
167
+ message({ action: :pass, value: pass }) do |msg|
168
+ puts "-1 #{msg}"
169
+ end
163
170
  end
@@ -177,13 +177,13 @@ class Atome
177
177
  new_atome
178
178
  end
179
179
 
180
- def store(params)
181
- params.each do |particle_to_save, data|
182
- # @!atome[particle_to_save]=data
183
- # instance_variable_set(particle_to_save,data)
184
- end
185
-
186
- end
180
+ # def store(params)
181
+ # params.each do |particle_to_save, data|
182
+ # # @!atome[particle_to_save]=data
183
+ # # instance_variable_set(particle_to_save,data)
184
+ # end
185
+ #
186
+ # end
187
187
 
188
188
  def history(filter = {})
189
189
  filter[:id] = @id
@@ -210,7 +210,7 @@ class Atome
210
210
  # option_found = params.values[0]
211
211
  # instance_variable_get(elem_code)["#{option_found}_code"] = user_proc
212
212
  # else
213
- instance_variable_get(elem_code)[element] = user_proc
213
+ instance_variable_get(elem_code)[element] = user_proc
214
214
  # end
215
215
  end
216
216
 
@@ -251,9 +251,9 @@ class Atome
251
251
  else
252
252
  instance_variable_get("@#{element}_code")[element]
253
253
  # instance_exec(@callback[element], proc_found)if proc_found.is_a? Proc
254
- end
254
+ end
255
255
  # array_of_proc_found.each do |proc_found|
256
- proc_found.call(return_params) if proc_found.is_a? Proc
256
+ proc_found.call(return_params) if proc_found.is_a? Proc
257
257
  # end if array_of_proc_found
258
258
 
259
259
  # if array_of_proc_found
@@ -381,26 +381,14 @@ class Atome
381
381
  end
382
382
 
383
383
  def server_receiver(params)
384
- # alert params
385
- # alert message_code
386
- calllbacks_found= instance_variable_get('@message_code')
387
- # we delete the default message created by atome
388
- calllbacks_found.delete(:message)
389
- # we get the oldest available callback, to treat it
390
- oldest_callback = calllbacks_found.delete(calllbacks_found.keys.first)
391
- params=params[:return] #TODO : format retrun data correctly instead of this line
392
- oldest_callback.call(params) if oldest_callback.is_a? Proc
393
- # callback(:message, params)
384
+ callback_found = Universe.messages[params[:message_id]]
385
+ callback_found.call(params) if callback_found.is_a? Proc
394
386
  end
395
387
 
396
388
  def init_websocket
397
- instance_variable_set('@message_code', {})
398
- # connection is particle (communication.rb)
399
389
  connection(@current_server)
400
390
  end
401
391
 
402
-
403
-
404
392
  def encrypt(string)
405
393
  # if RUBY_ENGINE.downcase == 'opal' || 'wasm32-wasi'
406
394
  # `sha256(#{string})`
@@ -9,6 +9,7 @@ class Universe
9
9
  @renderer_list = %i[html browser headless server log]
10
10
  @sanitizers = {}
11
11
  @specificities = {}
12
+ @messages = {}
12
13
 
13
14
  @categories = %w[ communication effect event geometry hierarchy identity material
14
15
  property security spatial time utility ]
@@ -20,6 +21,18 @@ class Universe
20
21
  class << self
21
22
  attr_reader :atomes, :renderer_list, :atome_list, :particle_list, :classes, :counter, :atomes_specificities
22
23
 
24
+ def messages
25
+ @messages
26
+ end
27
+
28
+ def store_messages(new_msg)
29
+ @messages[new_msg[:msg_nb]] = new_msg[:proc]
30
+ end
31
+
32
+ def delete_messages(msg_to_del)
33
+ @messages.delete(msg_to_del)
34
+ end
35
+
23
36
  def set_help(particle, &doc)
24
37
  @help[particle] = doc
25
38
  end
data/lib/atome/version.rb CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
  # return atome version
4
4
  class Atome
5
- VERSION = '0.5.6.1.9'
5
+ VERSION = '0.5.6.2.1'
6
6
  end
7
7
 
@@ -1,20 +1,39 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- A.message({ action: :insert, data: { table: :security, particle: :email, data: 'jeezs@jeezs.net' } })
4
- A.message({ action: :insert, data: { table: :security, particle: :name, data: 'jeezs' } }) do |data_received_from_server|
5
- puts "my first insert #{data_received_from_server}"
3
+ A.message({ action: :insert, data: { table: :security, particle: :password, data: 'my_pass'} }) do |datas|
4
+ puts "0 data received: #{datas}"
6
5
  end
6
+
7
+ A.message({ action: :insert, data: { table: :identity, particle: :name, data: 'jeezs' } }) do |data_received_from_server|
8
+ puts "1 my first insert #{data_received_from_server}"
9
+ end
10
+
11
+ A.message({ action: :insert, data: { table: :identity, particle: :name, data: 'jeezs2' } })
12
+
7
13
  A.message({ action: :query, data: { table: :identity } }) do |data_received_from_server|
8
- puts "another insert : #{data_received_from_server}"
14
+ puts "2 another insert : #{data_received_from_server}"
9
15
  end
16
+
10
17
  A.message({ action: :query, data: { table: :identity } }) do |data_received|
11
- puts "received : #{data_received}"
18
+ puts "3 received : #{data_received}"
12
19
  end
13
20
 
14
- A.message({ action: :insert, data: { table: :security, particle: :name, data: 'jeezs' } }) do |result|
15
- puts "insert done : #{result}"
21
+ A.message({ action: :insert, data: { table: :identity, particle: :name, data: 'jeezs3' } }) do |result|
22
+ puts "4 insert done : #{result}"
16
23
  end
17
24
 
18
- A.message({ action: :insert, data: { table: :security, particle: :name, data: 'jeezs' } }) do |result|
19
- puts "last message received: #{result}"
25
+ A.message({ action: :insert, data: { table: :identity, particle: :name, data: 'jeezs4' } }) do |result|
26
+ puts "5 last message received: #{result}"
20
27
  end
28
+
29
+ A.message({ action: :insert, data: { table: :security, particle: :name, data: 'john doe' } }) do |data_received_from_server|
30
+ puts "6 test 1 : #{data_received_from_server}"
31
+ end
32
+
33
+ A.message({ action: :insert, data: { table: :identity, particle: :tit, data: 'dummy' } }) do |data_received_from_server|
34
+ puts "7 test 2 : #{data_received_from_server}"
35
+ end
36
+
37
+ A.message({ action: :insert, data: { table: :unknown, particle: :name, data: 'dummy2' } }) do |data_received_from_server|
38
+ puts "test 3 : #{data_received_from_server}"
39
+ end
@@ -21,66 +21,52 @@ class EDen
21
21
  Database.connect_database
22
22
  end
23
23
 
24
- def self.terminal(cmd, option, ws, value, user, pass)
25
- {return: `#{cmd}` }
24
+ def self.terminal(cmd, option, ws, value, user, pass, message_id)
25
+ { return: `#{cmd}`, message_id: message_id }
26
26
  end
27
27
 
28
- def self.pass(cmd, option, ws, value, user, pass)
29
- {return: 'pass received' }
28
+ def self.pass(cmd, option, ws, value, user, pass, message_id)
29
+ { return: 'password received', message_id: message_id }
30
30
  end
31
31
 
32
- def self.init_db(cmd, option, ws, value, user, pass)
32
+ def self.login(cmd, option, ws, value, user, pass, message_id)
33
+ { return: 'login received', message_id: message_id }
34
+ end
35
+
36
+ def self.init_db(cmd, option, ws, value, user, pass, message_id)
33
37
  # Database.
34
- {return: 'database initialised' }
38
+ { return: 'database initialised', message_id: message_id }
35
39
  end
36
40
 
37
- def self.query(cmd, option, ws, value, user, pass)
41
+ def self.query(cmd, option, ws, value, user, pass, message_id)
38
42
  identity_table = db_access[cmd['table'].to_sym]
39
43
  result = identity_table.send(:all).send(:select)
40
- { action: :query, data: cmd['table'], return: result }
44
+ { action: :query, data: cmd['table'], return: "==> #{result}", message_id: message_id }
41
45
  end
42
46
 
43
- def self.insert(cmd, option, ws, value, user, pass)
44
- identity_table = db_access[:identity]
45
- identity_table.insert(email: 'tre@tre')
46
- { action: :insert, data: cmd, return: { email: 'tre@tre' } }
47
+ def self.insert(params, option, ws, value, user, pass, message_id)
48
+ table = params['table'].to_sym
49
+ particle = params['particle'].to_sym
50
+ data = params['data']
51
+ if db_access.table_exists?(table)
52
+ schema = db_access.schema(table)
53
+ if schema.any? { |col_def| col_def.first == particle }
54
+ identity_table = db_access[table.to_sym]
55
+ identity_table.insert(particle => data)
56
+ { action: :insert, return: "column : #{particle}, in table : #{table}, updated with : #{data}", message_id: message_id }
57
+ else
58
+ { action: :insert, return: "column not found: #{particle.class}", message_id: message_id }
59
+ end
60
+ else
61
+ { action: :insert, return: "table not found: #{table.class}", message_id: message_id }
62
+
63
+ end
47
64
  end
48
65
 
49
- # def self.authentification(cmd, option, ws, value, user, pass)
50
- # db = Database.connect_database
51
- # identity_items = db[:identity]
52
- # security_items = db[:security]
53
- #
54
- # identity_items.insert(email: 'tre@tre')
55
- # security_items.insert(password: 'poipoi')
56
- # # testtest= "Mails count: #{identity_items.count}"
57
- #
58
- # user_email = value["mail"]
59
- # user_password = value["pass"]
60
- #
61
- # # user_exists = identity_items.all.select{|item| item[:email]==user_email}
62
- # user_exists = identity_items.send(:all).send(:select) do |item|
63
- # item[:email] == user_email
64
- # end
65
- #
66
- # if user_exists.empty?
67
- # # "Mails count: #{identity_items.count}"
68
- # # "Mails count: #{identity_items.all}"
69
- # "Email non trouvé, erreur"
70
- # # Ask to the user if he wants to subscribe
71
- # # Send the basic template
72
- # else
73
- # "Email trouvé, cherche mdp"
74
- # # Verify password
75
- # # If password isn't ok, send error
76
- # # If the password is ok, send the user account template
77
- # end
78
- # end
79
-
80
- def self.file(source, operation, ws, value, user, pass)
66
+ def self.file(source, operation, ws, value, user, pass, message_id)
81
67
  file_content = File.send(operation, source, value).to_s
82
68
  file_content = file_content.gsub("'", "\"")
83
- {return: "=> operation: #{operation}, source: #{source} , content : #{file_content}" }
69
+ { return: "=> operation: #{operation}, source: #{source} , content : #{file_content}", message_id: message_id }
84
70
  end
85
71
 
86
72
  # return_message = EDen.safe_send(action_requested, data,option, current_user, user_pass)
@@ -91,7 +77,7 @@ class EDen
91
77
  if eden_methods.include?(method_sym)
92
78
  send(method_sym, *args)
93
79
  else
94
- {return: "forbidden action: #{method_name}" }
80
+ { return: "forbidden action: #{method_name}" }
95
81
  end
96
82
  end
97
83
  end
@@ -111,6 +97,7 @@ end
111
97
  class Database
112
98
 
113
99
  def self.table_exists?(table_name)
100
+ # code below must be removed but not fpr now
114
101
  eden = Sequel.connect("sqlite://eden.sqlite3")
115
102
  if eden.table_exists?(table_name)
116
103
  puts "La table #{table_name} existe dans la base de données."
@@ -323,19 +310,6 @@ class Database
323
310
  end
324
311
 
325
312
  class App < Roda
326
-
327
- # comment below when test will be done
328
- # File.delete("./eden.sqlite3") if File.exist?("./eden.sqlite3")
329
- eden = Database.connect_database
330
- items = eden[:atome]
331
-
332
- # populate the table
333
- items.insert(creator: 'moi')
334
- items.insert(creator: 'toi')
335
- items.insert(creator: 'vous')
336
- puts "Item count: #{items.count}"
337
- test = "Item count: #{items.count}"
338
- # puts "My name is: #{items(:creator)}"
339
313
  index_content = File.read("../src/index_server.html")
340
314
  opts[:root] = '../src'
341
315
  plugin :static, %w[/css /js /medias], root: '../src'
@@ -344,10 +318,8 @@ class App < Roda
344
318
  if Faye::WebSocket.websocket?(r.env)
345
319
  ws = Faye::WebSocket.new(r.env)
346
320
  ws.on :open do |event|
347
- ws.send({return: 'server ready' }.to_json)
348
- # ws.send('asking for synchro data'.to_json)
321
+ ws.send({ return: 'server ready' }.to_json)
349
322
  end
350
-
351
323
  ws.on(:message) do |event|
352
324
  json_string = event.data.gsub(/(\w+):/) { "\"#{$1}\":" }.gsub('=>', ':')
353
325
  full_data = JSON.parse(json_string)
@@ -356,9 +328,9 @@ class App < Roda
356
328
  value = full_data['value']
357
329
  option = full_data['option']
358
330
  current_user = full_data['user']
331
+ message_id = full_data['message_id']
359
332
  user_pass = full_data['pass']['global']
360
- # return_message = EDen.safe_send(action_requested, data, option, ws, value, current_user, user_pass)
361
- return_message = EDen.safe_send(action_requested, data, option, ws, value, current_user, user_pass)
333
+ return_message = EDen.safe_send(action_requested, data, option, ws, value, current_user, user_pass, message_id)
362
334
  ws.send(return_message.to_json)
363
335
  end
364
336
 
@@ -367,10 +339,8 @@ class App < Roda
367
339
  end
368
340
  ws.rack_response
369
341
  end
370
-
371
342
  index_content
372
343
  end
373
-
374
344
  end
375
345
 
376
346
  end
@@ -1,5 +1,4 @@
1
1
  const communication = {
2
- // websocket: new WebSocket('ws://localhost:9292'),
3
2
  websocket: null,
4
3
  initialize: function () {
5
4
  this.websocket = new WebSocket('ws://localhost:9292')
@@ -10,9 +9,7 @@ const communication = {
10
9
  };
11
10
 
12
11
  this.websocket.onmessage = function (event) {
13
- rubyVMCallback('message', "('" + event.data + "')")
14
-
15
- // rubyVMCallback("puts 'object ruby callback : " + event.data + "'")
12
+ rubyVMCallback('message', "('" + event.data + "')")
16
13
  };
17
14
 
18
15
  this.websocket.onclose = function (event) {
@@ -65,22 +62,15 @@ const communication = {
65
62
  }
66
63
  },
67
64
  connect: function (type, server, user, pass, atomes, particles) {
68
- this.websocket = new WebSocket(type+'://'+server);
65
+ this.websocket = new WebSocket(type + '://' + server);
69
66
  this.websocket.onopen = function (event) {
70
67
 
71
- // Opal.eval('A.init_database');
72
- // now new can exec user code : loadApplicationJs in index.html
73
- // rubyVMCallback("A.init_database");
68
+ // now new can exec user code : loadApplicationJs in index.html
74
69
  loadApplicationJs();
75
70
  rubyVMCallback("A.user_login");
76
- // rubyVMCallback("A.init_database");
77
71
  };
78
72
  this.websocket.onmessage = function (event) {
79
- // rubyVMCallback("puts 'object ruby callback : " + event.data + "'")
80
- // rubyVMCallback('message', "('" + event.data + "')")
81
- // rubyVMCallback("A.callback({ touch: '" + event.data + "' })");
82
- rubyVMCallback("A.server_receiver(" + event.data + ")");
83
- // alert(event.data)
73
+ rubyVMCallback("A.server_receiver(" + event.data + ")");
84
74
  };
85
75
 
86
76
  this.websocket.onclose = function (event) {
@@ -97,6 +87,7 @@ const communication = {
97
87
  },
98
88
  ws_sender: function (message) {
99
89
  // now we send the data to the server
90
+ // puts "--> message : #{message}"
100
91
  this.websocket.send(message)
101
92
  },
102
93
  }
@@ -130,8 +121,7 @@ const communication = {
130
121
  // }
131
122
 
132
123
 
133
-
134
- function controller_message(msg){
124
+ function controller_message(msg) {
135
125
  // message receiver from controller (Vie)
136
126
  console.log(msg)
137
127
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: atome
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.6.1.9
4
+ version: 0.5.6.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean-Eric Godard
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-02-12 00:00:00.000000000 Z
11
+ date: 2024-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: artoo