Class: QML::Reactive::UnboundProperty

Inherits:
Object
  • Object
show all
Defined in:
lib/qml/reactive/unbound_property.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, initial_value, initial_binding, owner, factory = nil) ⇒ UnboundProperty

Returns a new instance of UnboundProperty.



9
10
11
12
13
14
15
16
17
# File 'lib/qml/reactive/unbound_property.rb', line 9

def initialize(name, initial_value, initial_binding, owner, factory = nil)
  @name = name
  @initial_value = initial_value
  @initial_binding = initial_binding
  @owner = owner
  @notifier_signal = UnboundSignal.new(:"#{name}_changed", [:new_value], false, owner)
  @factory = factory
  @original = name
end

Instance Attribute Details

#initial_bindingObject (readonly)

Returns the value of attribute initial_binding.



7
8
9
# File 'lib/qml/reactive/unbound_property.rb', line 7

def initial_binding
  @initial_binding
end

#initial_valueObject (readonly)

Returns the value of attribute initial_value.



7
8
9
# File 'lib/qml/reactive/unbound_property.rb', line 7

def initial_value
  @initial_value
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/qml/reactive/unbound_property.rb', line 7

def name
  @name
end

#notifier_signalObject (readonly)

Returns the value of attribute notifier_signal.



7
8
9
# File 'lib/qml/reactive/unbound_property.rb', line 7

def notifier_signal
  @notifier_signal
end

#originalObject (readonly)

Returns the value of attribute original.



7
8
9
# File 'lib/qml/reactive/unbound_property.rb', line 7

def original
  @original
end

#ownerObject (readonly)

Returns the value of attribute owner.



7
8
9
# File 'lib/qml/reactive/unbound_property.rb', line 7

def owner
  @owner
end

Instance Method Details

#alias(name) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/qml/reactive/unbound_property.rb', line 19

def alias(name)
  notifier_signal_orig = @notifier_signal
  dup.tap do |property|
    property.instance_eval do
      @name = name
      @notifier_signal = notifier_signal_orig.alias(:"#{name}_changed")
    end
  end
end

#alias?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/qml/reactive/unbound_property.rb', line 29

def alias?
  @original != @name
end

#bind(obj) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/qml/reactive/unbound_property.rb', line 33

def bind(obj)
  return obj.instance_exec(&@factory) if @factory
  Property.new.tap do |p|
    p.value = @initial_value if @initial_value
    p.bind { obj.instance_eval &@initial_binding } if @initial_binding
  end
end