Mixin that makes the including class imitate a hash for backwards compatibility. The including class should use `attr_accessor` to declare attributes. @private
# File lib/rspec/core/metadata.rb, line 262 def self.included(klass) klass.extend ClassMethods end
# File lib/rspec/core/metadata.rb, line 300 def [](key) issue_deprecation(:[], key) if directly_supports_attribute?(key) get_value(key) else extra_hash_attributes[key] end end
# File lib/rspec/core/metadata.rb, line 310 def []=(key, value) issue_deprecation(:[]=, key, value) if directly_supports_attribute?(key) set_value(key, value) else extra_hash_attributes[key] = value end end
# File lib/rspec/core/metadata.rb, line 266 def to_h hash = extra_hash_attributes.dup self.class.hash_attribute_names.each do |name| hash[name] = __send__(name) end hash end
# File lib/rspec/core/metadata.rb, line 326 def directly_supports_attribute?(name) self.class.hash_attribute_names.include?(name) end
# File lib/rspec/core/metadata.rb, line 322 def extra_hash_attributes @extra_hash_attributes ||= {} end
# File lib/rspec/core/metadata.rb, line 330 def get_value(name) __send__(name) end
# File lib/rspec/core/metadata.rb, line 338 def hash_for_delegation to_h end
# File lib/rspec/core/metadata.rb, line 342 def issue_deprecation(method_name, *args) # no-op by default: subclasses can override end
# File lib/rspec/core/metadata.rb, line 334 def set_value(name, value) __send__(:"#{name}=", value) end