Class: WidgetBinding

Inherits:
Object
  • Object
show all
Includes:
Observer
Defined in:
lib/command_handlers/models/widget_binding.rb

Constant Summary collapse

@@property_type_converters =
{
  :text => Proc.new { |value| value.to_s },
  :items => Proc.new { |value| value.to_java :string}
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, property, translator = nil) ⇒ WidgetBinding

Returns a new instance of WidgetBinding.



11
12
13
14
15
# File 'lib/command_handlers/models/widget_binding.rb', line 11

def initialize(model, property, translator = nil)
  @widget = model
  @property = property
  @translator = translator || proc {|value| value}
end

Instance Attribute Details

#propertyObject (readonly)

Returns the value of attribute property.



6
7
8
# File 'lib/command_handlers/models/widget_binding.rb', line 6

def property
  @property
end

#widgetObject (readonly)

Returns the value of attribute widget.



6
7
8
# File 'lib/command_handlers/models/widget_binding.rb', line 6

def widget
  @widget
end

Instance Method Details

#evaluate_propertyObject



22
23
24
# File 'lib/command_handlers/models/widget_binding.rb', line 22

def evaluate_property
  @widget.widget.send(@property)
end

#update(value) ⇒ Object



16
17
18
19
20
21
# File 'lib/command_handlers/models/widget_binding.rb', line 16

def update(value)
  converted_value = translated_value = @translator.call(value)
  converter = @@property_type_converters[@property.to_sym]
  converted_value = converter.call(translated_value) if converter
  @widget.widget.send("set#{@property.camelcase(:upper)}", converted_value) unless evaluate_property == converted_value
end