Class: Freightrain::FreightViewModel

Inherits:
Object
  • Object
show all
Extended by:
ContainerHookable, ServiceHost, SignalHost, RegionHost
Defined in:
lib/freightrain/viewmodels/freight_view_model.rb

Direct Known Subclasses

FreightElementViewModel

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ContainerHookable

classes, container_options, extended, inherited, subclasses

Methods included from ServiceHost

extended, service

Methods included from RegionHost

extended, region

Methods included from SignalHost

extended, signal

Class Method Details

.container_optionsObject



10
11
12
# File 'lib/freightrain/viewmodels/freight_view_model.rb', line 10

def self.container_options
  return { :model => :prototype }
end

.new(*args, &block) ⇒ Object



21
22
23
24
25
26
# File 'lib/freightrain/viewmodels/freight_view_model.rb', line 21

def self.new(*args, &block)
  viewmodel = allocate
  viewmodel.bootstrap
  viewmodel.send(:initialize, *args, &block)
  return viewmodel
end

Instance Method Details

#bootstrapObject



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/freightrain/viewmodels/freight_view_model.rb', line 28

def bootstrap
  view = Freightrain[self.class.name.sub("Model", "").to_convention_sym]
  self.get_services
  self.build_regions
  self.create_signals
  view.hook_to_signals(self)
  self.services.each do |service_key|
    service = self.instance_variable_get("@#{service_key}")
    service.hook_to_signals(self, service_key)
  end
  view.data_source = self
  @view = view
end

#dialog(viewmodel_name, *args) ⇒ Object



14
15
16
17
18
19
# File 'lib/freightrain/viewmodels/freight_view_model.rb', line 14

def dialog(viewmodel_name, *args)
  dialog = Freightrain["#{viewmodel_name}_view_model".to_sym]      
  dialog.show_dialog(*args) do |*params|
    yield(*params) if block_given?
  end
end

#hideObject



51
52
53
# File 'lib/freightrain/viewmodels/freight_view_model.rb', line 51

def hide
  @view.control.hide
end

#showObject



42
43
44
45
46
47
48
49
# File 'lib/freightrain/viewmodels/freight_view_model.rb', line 42

def show      
  @view.control.show
  @regions.values.each do |region|
    region.on_show(@view)
    region.viewmodel.show
  end
  return @view.control
end

#viewObject



55
56
57
# File 'lib/freightrain/viewmodels/freight_view_model.rb', line 55

def view
  return @view
end