Class: Freightrain::FreightBinding

Inherits:
Object
  • Object
show all
Defined in:
lib/freightrain/binding/freight_binding.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(widget, options) ⇒ FreightBinding

Returns a new instance of FreightBinding.



8
9
10
11
12
13
14
15
# File 'lib/freightrain/binding/freight_binding.rb', line 8

def initialize(widget, options)
  @cache          = :__NOVALUE #TODO: this is necessary but really ugly - evaluate a possible replacement
  @widget         = widget
  @property       = options[:property].to_s.split('.')
  @path           = options[:path].to_s.split('.')
  @converter      = ConverterFactory.create(options[:converter]) || DefaultConverter.new #TODO: if in converterfactory?
  @force          = options[:force]
end

Instance Attribute Details

#data_sourceObject

Returns the value of attribute data_source.



6
7
8
# File 'lib/freightrain/binding/freight_binding.rb', line 6

def data_source
  @data_source
end

Instance Method Details

#commitObject



31
32
33
34
35
36
37
38
39
40
# File 'lib/freightrain/binding/freight_binding.rb', line 31

def commit()
  begin
    value = get(@widget, @property)
    set(@path, @converter.to(value), data_source)
  rescue Exception => ex #TODO: logger...
#        p "#{@widget.name} - commit"
#        p ex.message
#        p @path
  end
end

#updateObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/freightrain/binding/freight_binding.rb', line 17

def update()
  begin
    value = get(data_source, @path)
    if @force || value != @cache
      set(@property, @converter.from(value), @widget)
      @cache = value
    end
  rescue Exception => ex #TODO: logger...
    p "#{@widget.name} - update"
    p ex.message
    p @path
  end
end