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.
Class Method Summary collapse
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.
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ducktape/link.rb', line 29 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.
27 28 29 |
# File 'lib/ducktape/link.rb', line 27 def binding_source @binding_source end |
#converter ⇒ Object
WeakRef of Object
21 22 23 |
# File 'lib/ducktape/link.rb', line 21 def converter @converter end |
#expression ⇒ Object
WeakRef of Object
21 22 23 |
# File 'lib/ducktape/link.rb', line 21 def expression @expression end |
#mode ⇒ Object
WeakRef of Object
21 22 23 |
# File 'lib/ducktape/link.rb', line 21 def mode @mode end |
#source ⇒ Object
WeakRef of Object
21 22 23 |
# File 'lib/ducktape/link.rb', line 21 def source @source end |
#target ⇒ Object
WeakRef of Object
21 22 23 |
# File 'lib/ducktape/link.rb', line 21 def target @target end |
Class Method Details
.cleanup(*method_names) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/ducktape/link.rb', line 8 def cleanup(*method_names) method_names.each do |method_name| m = instance_method(method_name) define_method(method_name, ->(*args, &block) do return m.bind(self).(*args, &block) unless broken? unbind if @expression @target.object.remove_source if @target && @target.object @source, @target, @expression = nil end) end end |
Instance Method Details
#bind ⇒ Object
52 53 54 55 |
# File 'lib/ducktape/link.rb', line 52 def bind @expression.bind(@source.object, :value) nil end |
#broken? ⇒ Boolean
40 41 42 |
# File 'lib/ducktape/link.rb', line 40 def broken? !(@source && @target && @source.object && @target.object) end |
#forward? ⇒ Boolean
44 45 46 |
# File 'lib/ducktape/link.rb', line 44 def forward? BindingSource::PROPAGATE_TO_TARGET.include?(@mode) end |
#reverse? ⇒ Boolean
48 49 50 |
# File 'lib/ducktape/link.rb', line 48 def reverse? BindingSource::PROPAGATE_TO_SOURCE.include?(@mode) end |
#source_value ⇒ Object
72 73 74 75 |
# File 'lib/ducktape/link.rb', line 72 def source_value assert_mode :get, :source, :forward @converter.convert(@expression.value) end |
#target_value ⇒ Object
77 78 79 80 |
# File 'lib/ducktape/link.rb', line 77 def target_value assert_mode :get, :target, :reverse @converter.revert(@target.object.value) end |
#unbind ⇒ Object
57 58 59 60 |
# File 'lib/ducktape/link.rb', line 57 def unbind @expression.unbind nil end |
#update_source ⇒ Object
62 63 64 65 |
# File 'lib/ducktape/link.rb', line 62 def update_source assert_mode :set, :source, :reverse @expression.value = target_value end |
#update_target ⇒ Object
67 68 69 70 |
# File 'lib/ducktape/link.rb', line 67 def update_target assert_mode :set, :target, :forward @target.object.value = source_value end |