Class: Ducktape::Link
Defined Under Namespace
Classes: ModeError
Instance Attribute Summary collapse
-
#binding_source ⇒ Object
readonly
Returns the value of attribute binding_source.
-
#converter ⇒ Object
WeakRef of Object.
-
#expression ⇒ Object
WeakRef of Object.
-
#mode ⇒ Object
WeakRef of Object.
-
#source ⇒ Object
WeakRef of Object.
-
#target ⇒ Object
WeakRef of Object.
Instance Method Summary collapse
- #bind ⇒ Object
- #broken? ⇒ Boolean
- #forward? ⇒ Boolean
-
#initialize(binding_source, target) ⇒ Link
constructor
A new instance of Link.
- #reverse? ⇒ Boolean
- #source_value ⇒ Object
- #target_value ⇒ Object
- #unbind ⇒ Object
- #update_source ⇒ Object
- #update_target ⇒ Object
Constructor Details
#initialize(binding_source, target) ⇒ Link
Returns a new instance of Link.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ducktape/link.rb', line 15 def initialize(binding_source, target) @binding_source = binding_source @source = WeakReference.new(binding_source.source) @expression = Expression::BindingParser.parse(binding_source.path) @target = WeakReference.new(target) @converter = binding_source.converter @mode = binding_source.mode @expression.owner = self end |
Instance Attribute Details
#binding_source ⇒ Object (readonly)
Returns the value of attribute binding_source.
13 14 15 |
# File 'lib/ducktape/link.rb', line 13 def binding_source @binding_source end |
#converter ⇒ Object
WeakRef of Object
7 8 9 |
# File 'lib/ducktape/link.rb', line 7 def converter @converter end |
#expression ⇒ Object
WeakRef of Object
7 8 9 |
# File 'lib/ducktape/link.rb', line 7 def expression @expression end |
#mode ⇒ Object
WeakRef of Object
7 8 9 |
# File 'lib/ducktape/link.rb', line 7 def mode @mode end |
#source ⇒ Object
WeakRef of Object
7 8 9 |
# File 'lib/ducktape/link.rb', line 7 def source @source end |
#target ⇒ Object
WeakRef of Object
7 8 9 |
# File 'lib/ducktape/link.rb', line 7 def target @target end |
Instance Method Details
#bind ⇒ Object
38 39 40 41 |
# File 'lib/ducktape/link.rb', line 38 def bind with_cleanup { @expression.bind(@source.object, :value) } nil end |
#broken? ⇒ Boolean
26 27 28 |
# File 'lib/ducktape/link.rb', line 26 def broken? !(@source && @target && @source.object && @target.object) end |
#forward? ⇒ Boolean
30 31 32 |
# File 'lib/ducktape/link.rb', line 30 def forward? BindingSource::PROPAGATE_TO_TARGET.include?(@mode) end |
#reverse? ⇒ Boolean
34 35 36 |
# File 'lib/ducktape/link.rb', line 34 def reverse? BindingSource::PROPAGATE_TO_SOURCE.include?(@mode) end |
#source_value ⇒ Object
58 59 60 61 |
# File 'lib/ducktape/link.rb', line 58 def source_value assert_mode :get, :source, :forward with_cleanup { @converter.convert(@expression.value) } end |
#target_value ⇒ Object
63 64 65 66 |
# File 'lib/ducktape/link.rb', line 63 def target_value assert_mode :get, :target, :reverse with_cleanup { @converter.revert(@target.object.value) } end |
#unbind ⇒ Object
43 44 45 46 |
# File 'lib/ducktape/link.rb', line 43 def unbind with_cleanup { @expression.unbind } nil end |
#update_source ⇒ Object
48 49 50 51 |
# File 'lib/ducktape/link.rb', line 48 def update_source assert_mode :set, :source, :reverse with_cleanup { @expression.value = target_value } end |
#update_target ⇒ Object
53 54 55 56 |
# File 'lib/ducktape/link.rb', line 53 def update_target assert_mode :set, :target, :forward with_cleanup { @target.object.set_value source_value } end |