Class: Ducktape::BindableAttribute
- Inherits:
-
Object
- Object
- Ducktape::BindableAttribute
- Includes:
- Hookable
- Defined in:
- lib/ducktape/bindable_attribute.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Bindable.
-
#owner ⇒ Object
readonly
Bindable.
-
#value ⇒ Object
readonly
Bindable.
Instance Method Summary collapse
- #binding_source ⇒ Object
- #has_source? ⇒ Boolean
-
#initialize(owner, name) ⇒ BindableAttribute
constructor
:source_link # Link - link between source and target.
- #metadata ⇒ Object
-
#remove_source(reset = true) ⇒ Object
After unbinding the source the value can be reset, or kept.
- #reset_value ⇒ Object
- #set_value(value) {|@value| ... } ⇒ Object
- #to_s ⇒ Object
Methods included from Hookable
Constructor Details
#initialize(owner, name) ⇒ BindableAttribute
:source_link # Link - link between source and target
18 19 20 21 |
# File 'lib/ducktape/bindable_attribute.rb', line 18 def initialize(owner, name) @owner, @name, @source_link = owner, name.to_s, nil reset_value end |
Instance Attribute Details
#name ⇒ Object (readonly)
Bindable
13 14 15 |
# File 'lib/ducktape/bindable_attribute.rb', line 13 def name @name end |
#owner ⇒ Object (readonly)
Bindable
13 14 15 |
# File 'lib/ducktape/bindable_attribute.rb', line 13 def owner @owner end |
#value ⇒ Object (readonly)
Bindable
13 14 15 |
# File 'lib/ducktape/bindable_attribute.rb', line 13 def value @value end |
Instance Method Details
#binding_source ⇒ Object
23 24 25 |
# File 'lib/ducktape/bindable_attribute.rb', line 23 def binding_source @source_link.binding_source if @source_link end |
#has_source? ⇒ Boolean
27 28 29 |
# File 'lib/ducktape/bindable_attribute.rb', line 27 def has_source? !!@source_link end |
#metadata ⇒ Object
31 32 33 |
# File 'lib/ducktape/bindable_attribute.rb', line 31 def @owner.send(:metadata, @name) end |
#remove_source(reset = true) ⇒ Object
After unbinding the source the value can be reset, or kept. The default is to reset the target’s (self) value.
37 38 39 40 41 42 43 |
# File 'lib/ducktape/bindable_attribute.rb', line 37 def remove_source(reset = true) return unless @source_link src, @source_link = @source_link, nil src.unbind reset_value if reset src.binding_source end |
#reset_value ⇒ Object
45 46 47 |
# File 'lib/ducktape/bindable_attribute.rb', line 45 def reset_value set_value .default end |
#set_value(value) {|@value| ... } ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/ducktape/bindable_attribute.rb', line 49 def set_value(value) if value.is_a?(BindingSource) #attach new binding source replace_source value return @value unless @source_link.forward? #value didn't change value = @source_link.source_value end original_value, value = value, transform_value(value) return @value if value.equal?(@value) || value == @value # transformed value is the same? #set effective value old_value, @original_value, @value = @value, original_value, value yield @value if block_given? call_hooks :on_changed, owner, attribute: name.dup, value: @value, old_value: old_value @source_link.update_source if @source_link && @source_link.reverse? @value end |
#to_s ⇒ Object
70 71 72 |
# File 'lib/ducktape/bindable_attribute.rb', line 70 def to_s "#<#{self.class}:0x#{object_id.to_s(16)} @name=#{name}>" end |