lib/atome/kernel/generators/genesis.rb in atome-0.4.5.4 vs lib/atome/kernel/generators/genesis.rb in atome-0.4.7.0

- old
+ new

@@ -15,12 +15,10 @@ # genesis kernel module GenesisKernel # particle's methods def set_new_particle(particle, value, &proc) return false unless validation(particle) - - # instance_exec({ options: value }, &proc) if proc.is_a?(Proc) # now we exec the first optional method value = Genesis.run_optional_methods_helper("#{particle}_pre_render_proc".to_sym, { method: particle, value: value, atome: self, proc: proc }) # render option below Genesis.run_optional_methods_helper("#{particle}_render_proc".to_sym, @@ -28,72 +26,82 @@ # now we exec post render optional proc value = Genesis.run_optional_methods_helper("#{particle}_post_render_proc".to_sym, { method: particle, value: value, proc: proc }) broadcaster(particle, value) history(particle, value) + self end def get_new_particle(particle) return false unless validation(particle) + particle_instance_variable = "@#{particle}" - value_getted=instance_variable_get(particle_instance_variable) - Genesis.run_optional_methods_helper("#{particle}_getter_pre_proc".to_sym, { value: value_getted, atome: self }) + value_get = instance_variable_get(particle_instance_variable) + Genesis.run_optional_methods_helper("#{particle}_getter_pre_proc".to_sym, { value: value_get, atome: self }) end - def new_particle(particle, params, proc) + def new_particle(particle, params, proc, &method_proc) if params + if method_proc.is_a?(Proc) + params = instance_exec(params, &method_proc) + end set_new_particle(particle, params, &proc) else get_new_particle(particle) end end # atome's methods - def create_new_atomes(params, instance_var, _atome) - new_atome = Atome.new({}) - instance_variable_set(instance_var, new_atome) - # FIXME : move this to sanitizer and ensure that no reorder happen for "id" and "render" when - params.each do |param, value| - new_atome.send(param, value) - end - end - - def set_new_atome(atome, params, proc) - return false unless validation(atome) - - instance_var = "@#{atome}" - # now we exec the first optional method - params=Genesis.run_optional_methods_helper("#{atome}_pre_save_proc".to_sym, { value: params, proc: proc }) - create_new_atomes(params[:value], instance_var, atome) - # now we exec the second optional method - Genesis.run_optional_methods_helper("#{atome}_post_save_proc".to_sym, { value: params, proc: proc }) - @dna = "#{Atome.current_user}_#{Universe.app_identity}_#{Universe.atomes.length}" - self - end - def get_new_atome(atome) return false unless validation(atome) - # Genesis.run_optional_methods_helper("#{atome}_getter_pre_proc".to_sym, { value: false }) atome_instance_variable = "@#{atome}" - value_getted=instance_variable_get(atome_instance_variable) - Genesis.run_optional_methods_helper("#{atome}_getter_pre_proc".to_sym, { value: value_getted }) + value_get = instance_variable_get(atome_instance_variable) + Genesis.run_optional_methods_helper("#{atome}_getter_pre_proc".to_sym, { value: value_get }) end - def new_atome(atome, params, proc) + def new_atome(atome, params, userproc, &method_proc) if params + # the line below execute the proc associated to the method, ex Genesis.atome_creator(:color) do ...(proc) + params = instance_exec(params, &method_proc) if method_proc.is_a?(Proc) params = add_essential_properties(atome, params) params = sanitizer(params) - set_new_atome(atome, params, proc) + set_new_atome(atome, params, userproc) else get_new_atome(atome) end end + def set_new_atome(atome, params, userproc) + params[:bloc] = userproc + return false unless validation(atome) + + instance_var = "@#{atome}" + new_atome = Atome.new({}, &userproc) + # now we exec the first optional method + params = Genesis.run_optional_methods_helper("#{atome}_pre_save_proc".to_sym, { value: params, atome: new_atome, proc: userproc }) + new_atome = create_new_atomes(params[:value], instance_var, new_atome, &userproc) + # now we exec the second optional method + Genesis.run_optional_methods_helper("#{atome}_post_save_proc".to_sym, { value: params, atome: new_atome, proc: userproc }) + @dna = "#{Atome.current_user}_#{Universe.app_identity}_#{Universe.atomes.length}" + new_atome + end + + def create_new_atomes(params, instance_var, new_atome, &userproc) + # new_atome = Atome.new({}, &userproc) + Universe.atomes_add(new_atome, params[:id]) + instance_variable_set(instance_var, new_atome) + # FIXME : move this to sanitizer and ensure that no reorder happen for "id" and "render" when + params.each do |param, value| + new_atome.send(param, value) + end + new_atome + end + def additional_atomes(atome, params) atome_instance_variable = "@#{atome}" if params instance_variable_get(atome_instance_variable).additional(params) else @@ -112,24 +120,29 @@ def self.atome_creator_option(property_name, &proc) @optionals_methods[property_name] = proc end - def self.run_optional_methods_helper(method_name, params, atome=nil) + def self.run_optional_methods_helper(method_name, params, atome = nil) + proc = nil proc = @optionals_methods[method_name] if @optionals_methods - instance_exec(params,atome, &proc) if proc.is_a?(Proc) - end + # it run all methods that looks like : + # bloc_render_proc + # render_getter_pre_proc + # bloc_post_render_proc - # #fIXME : we may have to remove the 2 methods below its only for test + params[:atome].instance_exec(params, atome, &proc) if proc.is_a?(Proc) - # render methods generator + + end + def self.generate_html_renderer(method_name, &methods_proc) current_renderer = :html generated_method_name = "#{method_name}_#{current_renderer}".to_sym Atome.define_method generated_method_name do |value, atome, &user_proc| - instance_exec(value, atome, user_proc, &methods_proc) if methods_proc.is_a?(Proc) + params[:atome].instance_exec(value, atome, user_proc, &methods_proc) if methods_proc.is_a?(Proc) end end def self.generate_server_renderer(method_name, &methods_proc) current_renderer = :headless @@ -164,16 +177,16 @@ Genesis.atome_creator_option("#{method_name}_pre_save_proc".to_sym) do |params, proc| # we return the value params end - Genesis.atome_creator_option("#{method_name}_sanitizer_proc".to_sym) do |params,atome, proc| + Genesis.atome_creator_option("#{method_name}_sanitizer_proc".to_sym) do |params, atome, proc| # we return the value params end - Genesis.atome_creator_option("#{method_name}_getter_pre_proc".to_sym) do |params,atome, proc| + Genesis.atome_creator_option("#{method_name}_getter_pre_proc".to_sym) do |params, atome, proc| # we return the value params[:value] end end @@ -192,17 +205,17 @@ end generate_renderers_methods(method_name) end # we create the easy methods here : ¬ - def self.atome_creator(method_name, &proc) - instance_exec(method_name, &proc) if proc.is_a?(Proc) + def self.atome_creator(method_name, &method_proc) + # we add the new method to the atome's collection of methods Utilities.atome_list(method_name) # we define many methods : easy, method=,pluralised and the fasts one, here is the easy Atome.define_method method_name do |params = nil, &user_proc| - new_atome(method_name, params, user_proc) + new_atome(method_name, params, user_proc, &method_proc) end # no we also add the method= for easy setting Atome.define_method("#{method_name}=") do |params, &user_proc| new_atome(method_name, params, user_proc) end @@ -247,15 +260,14 @@ generate_renderers_methods(method_name) # now we generate all optional methods optional_particle_methods(method_name) end - def self.particle_creator(method_name, &proc) - instance_exec(method_name, &proc) if proc.is_a?(Proc) + def self.particle_creator(method_name, &method_proc) # we add the new method to the particle's collection of methods Utilities.particle_list(method_name) Atome.define_method method_name do |params = nil, &user_proc| - new_particle(method_name, params, user_proc) + new_particle(method_name, params, user_proc, &method_proc) end # no we also add the method= for easy setting Atome.define_method("#{method_name}=") do |params, &user_proc| new_particle(method_name, params, user_proc) end