Class: Nemo::Examples::PersonEditor::Session

Inherits:
Wee::Session
  • Object
show all
Defined in:
lib/nemo/examples/person_editor.rb

Instance Method Summary collapse

Constructor Details

#initializeSession

Initialize the Wee session



69
70
71
72
73
74
# File 'lib/nemo/examples/person_editor.rb', line 69

def initialize
  super do
    self.root_component = Nemo::Examples::PersonEditor::Root.new
    self.page_store = Wee::Utils::LRUCache.new(25) # backtrack up to 25 pages
  end
end

Instance Method Details

#domainmodelObject

Create a new DomainModel and populate with data. Define and store in a constant on creation, return existing if already defined.



99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/nemo/examples/person_editor.rb', line 99

def domainmodel
  unless Nemo::Examples::PersonEditor.const_defined?(:Model)
    Nemo::Examples::PersonEditor.const_set(:Model, Nemo::Examples::PersonEditor::DomainModel.new)
    father = person(:name=>'Joe',  :sex=>true,  :birthday=>Date.new(1950,1,1))
    mother = person(:name=>'Jane', :sex=>false, :birthday=>Date.new(1960,1,1))
    child1 = person(:name=>'Lisa', :sex=>false, :birthday=>Date.new(1982,1,1), :father=>father, :mother=>mother)
    child2 = person(:name=>'Liza', :sex=>false, :birthday=>Date.new(1978,1,1), :father=>father, :mother=>mother)
    father.phone_numbers << phone_number(:number=>'281-328-1328', :type=>'home')
    child1.phone_numbers << phone_number(:number=>'132-813-2813', :type=>'work')
    [father, mother, child1, child2].each { |p| Nemo::Examples::PersonEditor::Model.add_person(p) }
  end
  Nemo::Examples::PersonEditor::Model
end

#person(hash = Hash.new) ⇒ Object

Create a new Person

person(:name=>'Joe', birthday=Date.new(1950,1,1))


80
81
82
83
84
# File 'lib/nemo/examples/person_editor.rb', line 80

def person(hash=Hash.new)
  obj = Nemo::Examples::PersonEditor::Person.new
  hash.each { |k,v| obj.send(k.to_s+'=', v) }
  obj
end

#phone_number(hash = Hash.new) ⇒ Object

Create a new PhoneNumber

phone_number(:type=>'home', :number=>'281-328-1328')


90
91
92
93
94
# File 'lib/nemo/examples/person_editor.rb', line 90

def phone_number(hash=Hash.new)
  obj = Nemo::Examples::PersonEditor::PhoneNumber.new
  hash.each { |k,v| obj.send(k.to_s+'=', v) }
  obj
end