Module: HttpObjects::Headers::Attributes

Included in:
HttpObjects::Hash
Defined in:
lib/http_objects/headers/attributes.rb

Overview

Public: Extend this module and you be able to retrieve and register attributes in your class.

Examples

class SampleAttributes
  extend HttpObjects::Headers::Attributes
  register_attribute "MyAttributeName", MyObject do |object|
    # optional hook
  end
end

SampleAttributes.attributes # => {"MyAttributeName" => MyObject}

Instance Method Summary collapse

Instance Method Details

#attributesObject

Returns Hash of registered attributes.



19
20
21
# File 'lib/http_objects/headers/attributes.rb', line 19

def attributes
  @attributes ||= {}
end

#register_attribute(name, attr_class) {|name, attr_class| ... } ⇒ Object

Public: Register on attributes, the pair name and attr_class.

name - String identifying attribute. attr_class - Class to identify the attribute.

Yields name and attr_class informed. Optional.

Returns nothing.

Yields:

  • (name, attr_class)


31
32
33
34
# File 'lib/http_objects/headers/attributes.rb', line 31

def register_attribute(name, attr_class)
  attributes[name] = attr_class
  yield(name, attr_class) if block_given?
end