lib/atome/genesis/generators/identity.rb in atome-0.5.3.8.1 vs lib/atome/genesis/generators/identity.rb in atome-0.5.3.8.8
- old
+ new
@@ -1,58 +1,101 @@
# frozen_string_literal: true
-new({ particle: :attached })
-new({ sanitizer: :attached }) do |params|
- params = [params] unless params.instance_of? Array
- params
+new({ particle: :attach })
+new({ sanitizer: :attach }) do |parents_ids|
+ parents_ids = parents_ids.value if parents_ids.instance_of? Atome
+ parents_ids = [parents_ids] unless parents_ids.instance_of?(Array)
+ parents_ids.each do |parents_id|
+ parents_id = parents_id.value if parents_id.instance_of? Atome
+ parents_found = grab(parents_id)
+ # TODO : factorise the code below
+ current_type = atome[:type]
+ parents_found.atome[current_type] = [] unless parents_found.atome[current_type]
+
+ # the condition below is needed when user passed a hash instead of the id of the child cf :
+ parent_type_container = if parents_found.atome[current_type].instance_of? Array
+ parents_found.atome[current_type]
+ else
+ [parents_found.atome[current_type][:id]]
+ end
+ # here we add the child into it's parents type container
+ parent_type_container << atome[:id]
+ # TODO : factorise the code above
+ parents_found.atome[:attached] = [] unless parents_found.atome[:attached]
+ parents_found.atome[:attached] << atome[:id]
+ end
+ # atome[:parents]=atome[:parents] | parents_ids
+ # atome[:parents].concat(parents_ids).uni
+ # puts "==> #{id} : #{self}"
+ # puts "====> id : #{id}, #{parents_ids} #{atome[:parents]}, #{atome[:parents].class} : #{atome[:parents].class}"
+ parents_ids
end
-new({ pre: :attached }) do |children_ids|
+
+new({ particle: :attached })
+new({ sanitizer: :attached }) do |children_ids|
+ children_ids = children_ids.value if children_ids.instance_of? Atome
+ children_ids = [children_ids] unless children_ids.instance_of?(Array)
children_ids.each do |child_id|
child_id = child_id.value if child_id.instance_of? Atome
child_found = grab(child_id)
parents_found = @atome[:id]
- child_found.family(parents_found)
+ # TODO : factorise the code below
+ child_found_type = child_found.type.value
+ @atome[child_found_type] = [] unless @atome[child_found_type]
+
+ # the condition below is needed when user passed a hash instead of the id of the child cf :
+ # circle(color: {red: 0, green: 1}) instead of color({id: :the_col}); circle(color: [:the_col])
+ child_type_container = if @atome[child_found_type].instance_of? Array
+ @atome[child_found_type]
+ else
+ [@atome[child_found_type][:id]]
+ end
+ child_type_container << child_id
+ # TODO : factorise the code above
+
+ # child_found.family(parents_found)
child_found.atome[:attach] = [parents_found]
end
end
-new({ particle: :type })
-new({ particle: :children })
-new ({ sanitizer: :children }) do |params|
- # TODO factorise the line below and 'sanitized_params' for all particle type of Array
- params = [params] unless params.instance_of? Array
- sanitized_params = []
- params.each do |child_id|
- child_id = child_id.value if child_id.instance_of? Atome
- sanitized_params << child_id
- child_found = grab(child_id)
- parents_found = @atome[:id]
- # FIXME : broadcast may malfunction because of the commented line below,
- # FIXME suite : if uncomment object hierarchy is broken (cf Vie Project)
- # FIXME : parent child problem may be caused by th eline below
- child_found.family(parents_found)
- child_found.atome[:parents] = [parents_found]
- end
- sanitized_params
-end
+new({ particle: :detached, store: false })
-new({ particle: :parents })
-new({ sanitizer: :parents }) do |params|
- params = [params] unless params.instance_of? Array
- sanitized_params = []
- params.each do |parents_id|
- parents_id = parents_id.value if parents_id.instance_of? Atome
- sanitized_params << parents_id
- parents_found = grab(parents_id)
- family(parents_id)
- parents_found.atome[:children] << atome[:id]
+new({ sanitizer: :detached }) do |values|
+ if values.instance_of? Array
+ values.each do |value|
+ detach_atome(value)
+ end
+ else
+ detach_atome(values)
+ # we sanitize the values so it always return an array to the renderer
+ values=[values]
end
- sanitized_params
+ values
end
-new({ particle: :family })
-new({ particle: :link })
+new({ particle: :type })
+
+# new({ particle: :parents })
+# new({ sanitizer: :parents }) do |params|
+# params = [params] unless params.instance_of? Array
+# sanitized_params = []
+# params.each do |parents_id|
+# parents_id = parents_id.value if parents_id.instance_of? Atome
+# sanitized_params << parents_id
+# parents_found = grab(parents_id)
+# # TODO : factorise the code below
+# current_type = atome[:type]
+# parents_found.atome[current_type] = [] unless parents_found.atome[current_type]
+# parents_found.atome[current_type] << atome[:id]
+# # TODO : factorise the code above
+# # TODO : check if we can remove the family
+# family(parents_id)
+# end
+# sanitized_params
+# end
+
+# new({ particle: :family })
new({ particle: :id })
new({ sanitizer: :id }) do |params|
if @atome[:id] != params
Universe.update_atome_id(params, self, @atome[:id])
else
@@ -60,22 +103,10 @@
end
params
end
new({ particle: :name })
new({ particle: :active })
-new({ particle: :attach })
-new({ pre: :attach }) do |parents_ids|
- parents_ids.each do |parents_id|
- parents_id = parents_id.value if parents_id.instance_of? Atome
- parents_found = grab(parents_id)
- family(parents_id)
- parents_found.atome[:attached] = [] unless parents_found.atome[:attached]
- parents_found.atome[:attached] << atome[:id]
- end
-end
-new({ particle: :detached }) do |value|
- attached.value.delete(value)
-end
+
new({ particle: :intricate, type: :array })
new({ particle: :clones }) do |clones_found|
clones_found.each_with_index do |clone_found, index|
particles_intricated = clone_found[:intricate] ||= []
clone_id = "#{particles[:id]}_clone_#{index}"