Sha256: 984d7cf27db601d1e48ec523ee92968d35f443b450b72b8a3ca920fc32da8e99
Contents?: true
Size: 1.12 KB
Versions: 2
Compression:
Stored size: 1.12 KB
Contents
module MotionBindable # # Represents a binding strategy. Designed to be as flexible as possible. # class Strategy @strategies_map = [{ class: Strategy, candidates: [Object] }] def self.register_strategy(strategy, *objects) @strategies_map << { class: strategy, candidates: objects } end def self.find_by_reference(object) @strategies_map.reverse.find do |h| h[:candidates].one? { |e| object.is_a? e } end.fetch(:class) end attr_accessor :object attr_accessor :bound def initialize(object, attr_name) @attr_name = attr_name.to_sym self.object = object end def bind(bound) self.bound = bound on_bind self end def unbind end # You can either choose to just override `#refresh` for objects that can't # be bound with callbacks. Or override `#on_bind` for objects that can be # bound with a callback. def refresh; end def on_bind refresh end def attribute object.send(@attr_name) end def attribute=(value) object.send(:"#{@attr_name.to_s}=", value) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
motion_bindable-0.1.1 | lib/motion_bindable/strategy.rb |
motion_bindable-0.1.0 | lib/motion_bindable/strategy.rb |