module Ducktape::Bindable
Public Class Methods
extended(_)
click to toggle source
# File lib/ducktape/bindable.rb, line 74 def self.extended(_) raise 'Cannot extend, only include.' end
included(base)
click to toggle source
# File lib/ducktape/bindable.rb, line 64 def self.included(base) base.extend ClassMethods return unless base.is_a?(Module) included = base.respond_to?(:included) && base.method(:included) base.define_singleton_method(:included, ->(c) do included.(c) if included c.extend(ClassMethods) end) end
Public Instance Methods
bind(attr_name, *args)
click to toggle source
# File lib/ducktape/bindable.rb, line 78 def bind(attr_name, *args) BindingSource.new(*args).tap { |source| send "#{attr_name}=", source } end
bindable_attr?(attr_name)
click to toggle source
# File lib/ducktape/bindable.rb, line 82 def bindable_attr?(attr_name) !!metadata(attr_name) end
binding_source(attr_name)
click to toggle source
# File lib/ducktape/bindable.rb, line 86 def binding_source(attr_name) return unless bindable_attr?(attr_name) get_bindable_attr(attr_name).binding_source end
clear_bindings(reset = true)
click to toggle source
# File lib/ducktape/bindable.rb, line 91 def clear_bindings(reset = true) bindable_attrs.each { |_, attr| attr.remove_source(reset) } nil end
on_changed(attr_name, hook = nil, &block)
click to toggle source
# File lib/ducktape/bindable.rb, line 96 def on_changed(attr_name, hook = nil, &block) return nil unless block || hook get_bindable_attr(attr_name).on_changed(hook, &block) hook || block end
unbind_source(attr_name)
click to toggle source
# File lib/ducktape/bindable.rb, line 102 def unbind_source(attr_name) get_bindable_attr(attr_name).remove_source nil end
unhook_on_changed(attr_name, hook)
click to toggle source
# File lib/ducktape/bindable.rb, line 107 def unhook_on_changed(attr_name, hook) return nil unless hook get_bindable_attr(attr_name).remove_hook(:on_changed, hook) hook end