Class: Ducktape::BindableAttribute

Inherits:
Object
  • Object
show all
Includes:
Hookable
Defined in:
lib/ducktape/bindable_attribute.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Hookable

#add_hook, #clear_hooks, extended, included, #remove_hook

Constructor Details

#initialize(owner, name) ⇒ BindableAttribute

:source # Link - link between source and target



18
19
20
21
22
# File 'lib/ducktape/bindable_attribute.rb', line 18

def initialize(owner, name)
  @owner, @name, = owner, name.to_s
  @source = nil
  reset_value
end

Instance Attribute Details

#nameObject (readonly)

Bindable



13
14
15
# File 'lib/ducktape/bindable_attribute.rb', line 13

def name
  @name
end

#ownerObject (readonly)

Bindable



13
14
15
# File 'lib/ducktape/bindable_attribute.rb', line 13

def owner
  @owner
end

#valueObject

Bindable



13
14
15
# File 'lib/ducktape/bindable_attribute.rb', line 13

def value
  @value
end

Instance Method Details

#binding_sourceObject



24
25
26
27
# File 'lib/ducktape/bindable_attribute.rb', line 24

def binding_source
  return unless @source
  @source.binding_source
end

#has_source?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/ducktape/bindable_attribute.rb', line 29

def has_source?
  !!@source
end

#metadataObject



33
34
35
# File 'lib/ducktape/bindable_attribute.rb', line 33

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.



39
40
41
42
43
44
45
# File 'lib/ducktape/bindable_attribute.rb', line 39

def remove_source(reset = true)
  return unless @source
  src, @source = @source, nil
  src.unbind
  reset_value if reset
  src.binding_source
end

#reset_valueObject



47
48
49
# File 'lib/ducktape/bindable_attribute.rb', line 47

def reset_value
  set_value(.default)
end

#to_sObject



55
56
57
# File 'lib/ducktape/bindable_attribute.rb', line 55

def to_s
  "#<#{self.class}:0x#{object_id.to_s(16)} @name=#{name}>"
end