Module: Ducktape::Bindable::ClassMethods
- Defined in:
- lib/ducktape/bindable.rb
Instance Method Summary collapse
- #bindable(name, options = {}) ⇒ Object
-
#metadata(name) ⇒ Object
TODO improve metadata search.
Instance Method Details
#bindable(name, options = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ducktape/bindable.rb', line 18 def bindable(name, = {}) name = name.to_s [:access] ||= :both m = BindableAttributeMetadata.new((name) || name, ) [name] = m raise InconsistentAccessorError.new(true, name) if [:access] == :writeonly && [:getter] raise InconsistentAccessorError.new(false, name) if [:access] == :readonly && [:setter] define_method name, [:getter] || ->() { get_value(name) } unless [:access] == :writeonly unless [:access] == :readonly define_method "#{name}=", [:setter] || ->(value) { set_value(name, value) } end nil end |
#metadata(name) ⇒ Object
TODO improve metadata search
35 36 37 38 39 40 41 42 43 |
# File 'lib/ducktape/bindable.rb', line 35 def (name) name = name.to_s m = [name] return m if m a = ancestors.find { |a| a != self && a.respond_to?(:metadata) } return nil unless a && (m = a.(name)) m = m.dup [name] = m end |