Module: GenesisKernel

Included in:
Genesis
Defined in:
lib/atome/kernel/generators/genesis.rb

Overview

genesis kernel

Instance Method Summary collapse

Instance Method Details

#additional_atomes(atome, params) ⇒ Object



94
95
96
97
98
99
100
101
# File 'lib/atome/kernel/generators/genesis.rb', line 94

def additional_atomes(atome, params)
  atome_instance_variable = "@#{atome}"
  if params
    instance_variable_get(atome_instance_variable).additional(params)
  else
    instance_variable_get(atome_instance_variable).additional
  end
end

#create_new_atomes(params, instance_var, atome) ⇒ Object

atome's methods



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/atome/kernel/generators/genesis.rb', line 49

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
  # creating an atome using Atome.new
  params={type: atome}.merge(params)
  # we extract render to ensure it's the first element of the hash
  params={render: params.delete(:render)}.merge(params)
  params.each do |param, value|
    new_atome.send("set_#{param}", value)
  end
end

#get_new_atome(atome) ⇒ Object



75
76
77
78
79
80
81
# File 'lib/atome/kernel/generators/genesis.rb', line 75

def get_new_atome(atome)
  return false unless validation(atome)

  Genesis.run_optional_methods_helper("#{atome}_getter_pre_proc".to_sym)
  atome_instance_variable = "@#{atome}"
  instance_variable_get(atome_instance_variable)
end

#get_new_particle(particle) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/atome/kernel/generators/genesis.rb', line 31

def get_new_particle(particle)
  return false unless validation(particle)

  Genesis.run_optional_methods_helper("#{particle}_getter_pre_proc".to_sym)
  particle_instance_variable = "@#{particle}"
  instance_variable_get(particle_instance_variable)
end

#new_atome(atome, params, proc) ⇒ Object



83
84
85
86
87
88
89
90
91
92
# File 'lib/atome/kernel/generators/genesis.rb', line 83

def new_atome(atome, params, proc)
  if params
    params = add_essential_properties(atome, params)
    params = sanitizer(params)
    set_new_atome(atome, params, proc)

  else
    get_new_atome(atome)
  end
end

#new_particle(particle, params, proc) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/atome/kernel/generators/genesis.rb', line 39

def new_particle(particle, params, proc)
  if params
    set_new_particle(particle, params, &proc)
  else
    get_new_particle(particle)
  end
end

#set_new_atome(atome, params, proc) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/atome/kernel/generators/genesis.rb', line 62

def set_new_atome(atome, params, proc)
  return false unless validation(atome)

  instance_var = "@#{atome}"
  # now we exec the method specific to the type if it exist
  instance_exec({ options: params }, &proc) if proc.is_a?(Proc)
  # now we exec the first optional method
  Genesis.run_optional_methods_helper("#{atome}_pre_save_proc".to_sym)
  create_new_atomes(params, instance_var,atome)
  Genesis.run_optional_methods_helper("#{atome}_post_save_proc".to_sym)
  @dna = "#{Atome.current_user}_#{Universe.app_identity}_#{Universe.atomes.length}"
end

#set_new_particle(particle, value, &proc) ⇒ Object

particle's methods



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/atome/kernel/generators/genesis.rb', line 17

def set_new_particle(particle, value, &proc)
  return false unless validation(particle)

  Genesis.run_optional_methods_helper("#{particle}_pre_save_proc".to_sym)
  particle_instance_variable = "@#{particle}"
  instance_exec({ options: value }, &proc) if proc.is_a?(Proc)
  instance_variable_set(particle_instance_variable, value)
  Genesis.run_optional_methods_helper("#{particle}_pre_render_proc".to_sym)
  render_engine(particle, value, self, &proc)
  Genesis.run_optional_methods_helper("#{particle}_post_render_proc".to_sym)
  broadcaster(particle, value)
  history(particle, value)
end