lib/atome/genesis/genesis.rb in atome-0.5.6.3.9 vs lib/atome/genesis/genesis.rb in atome-0.5.6.4.0

- old
+ new

@@ -4,11 +4,11 @@ class Genesis class << self def create_particle(element, store, render) Atome.define_method "set_#{element}" do |params, &user_proc| - particle_creation(element, params, store, render, &user_proc) + particle_creation(element, params, store, render, &user_proc) end end def build_particle(particle_name, options = {}, &particle_proc) type = options[:type] @@ -70,12 +70,21 @@ def build_option(method_name, method_proc) Universe.add_optional_method(method_name.to_sym, method_proc) end def new_particle(element, store, render, &_method_proc) + # unless @id + # alert self.id + # end + Atome.define_method element do |params = nil, &user_proc| + # if @id + # alert "======> #{self.class}" @history[element] ||= [] + # else + # alert "======> #{self.inspect}" + # end if (params || params == false) && write_auth(element) params = particle_sanitizer(element, params, &user_proc) # the line below execute the main code when creating a new particle # ex : new({ particle: :my_particle } do.... # instance_exec(params, user_proc, &method_proc) if method_proc.is_a?(Proc) @@ -85,11 +94,11 @@ collect.each do |collected_found| grab(collected_found).send(element, params, &user_proc) end end - computed_params= send("set_#{element}", params, &user_proc) # sent to : create_particle / Atome.define_method "set_#{element}" + computed_params = send("set_#{element}", params, &user_proc) # sent to : create_particle / Atome.define_method "set_#{element}" # we historicize all write action below # we add the changes to the stack that must be synchronised Universe.historicize(@id, :write, element, params) computed_params @@ -106,11 +115,13 @@ # TODO : create a fast method to get particle: eg: # Atome.define_method "set_#{element}" ... => send("set_#{element}" else "send a valid password to read #{element} value" end - + # else + # + # end end end def additional_particle_methods(element, store, rendering, &method_proc) # it allow the creation of method like top=, rotate=, ... @@ -160,10 +171,17 @@ Atome.define_method "set_#{element}" do |params, &user_proc| # we generate the corresponding module here: # Object.const_set(element, Module.new) # we add the newly created atome to the list of "child in it's category, eg if it's a shape we add the new atome # to the shape particles list : @!atome[:shape] << params[:id] - Atome.new(params, &user_proc) + # Atome.new(params, &user_proc) + + if Universe.atomes[params[:id]] + # if atome id already exist we grab the previous one + grab(params[:id]) + else + Atome.new(params, &user_proc) + end # Now we return the newly created atome instead of the current atome that is the parent cf: b=box; c=b.circle end end