module Ducktape::Bindable::ClassMethods

Public Instance Methods

bindable(name, options = {}) click to toggle source
# File lib/ducktape/bindable.rb, line 18
def bindable(name, options = {})
  name = name.to_s
  bindings_metadata[name] = metadata = BindableAttributeMetadata.new(metadata(name) || name, options)
  define_getter metadata
  define_setter metadata
  nil
end
metadata(name) click to toggle source
# File lib/ducktape/bindable.rb, line 26
def metadata(name)
  name = name.to_s

  meta = ancestors.find do |ancestor|
    bindings = ancestor.instance_variable_get(:@bindings_metadata)
    meta = bindings && bindings[name]
    break meta if meta
  end

  return unless meta
  bindings_metadata[name] = meta
end

Private Instance Methods

bindings_metadata() click to toggle source
# File lib/ducktape/bindable.rb, line 41
def bindings_metadata
  @bindings_metadata ||= {}
end
define_getter(metadata) click to toggle source
# File lib/ducktape/bindable.rb, line 45
def define_getter(metadata)
  if metadata.access == :writeonly
    raise InconsistentAccessorError.new(true, @name) if metadata.getter
    return
  end

  define_method metadata.name, metadata.getter_proc
end
define_setter(metadata) click to toggle source
# File lib/ducktape/bindable.rb, line 54
def define_setter(metadata)
  if metadata.access == :readonly
    raise InconsistentAccessorError.new(false, @name) if metadata.setter
    return
  end

  define_method "#{metadata.name}=", metadata.setter_proc
end