module Glimmer::DataBinding::ObservableHashable

Represents a Hash-like object with attributes writable via :[]= store method like Hash, Struct, and OpenStruct Expects including class to have the following methods:

Constants

OBSERVED_STORE_METHOD

Public Instance Methods

add_key_writer_observer(key = nil, options) click to toggle source
# File lib/glimmer/data_binding/observable_hashable.rb, line 57
def add_key_writer_observer(key = nil, options)
  ensure_array_object_observer(key, self[key], nil, options)
  begin
    method('__original__store')
  rescue
    define_singleton_method('__original__store', store_method)
    define_singleton_method('[]=', &OBSERVED_STORE_METHOD.call(options))
  end
rescue => e
  #ignore writing if no key writer exists
  Glimmer::Config.logger.debug {"No need to observe store method: '[]='\n#{e.message}\n#{e.backtrace.join("\n")}"}
end
store_method() click to toggle source
# File lib/glimmer/data_binding/observable_hashable.rb, line 70
def store_method
  self.class.instance_method('[]=') rescue self.method('[]=')
end