Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion lib/context_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,29 @@ def set_units(units)
units.map { |k, v| set_unit(k, v) }
end

##
# Fetches the UID for a named unit type.
# @param [String, Symbol] unit_type - The unit type key; converted to a symbol for lookup.
# @return [Object, nil] The UID stored for the given unit type, or nil if none exists.
def unit(unit_type)
@units[unit_type.to_sym]
end

##
# Merge the given attributes into the config's attributes, converting keys to symbols.
# @param [Hash] attributes - Mapping of attribute names to values; keys will be converted to symbols before being merged.
# @return [ContextConfig] self for method chaining.
def set_attributes(attributes)
@attributes.merge!(attributes.transform_keys(&:to_sym))
self
end

##
# Set a single attribute on the context.
# The attribute key is converted to a symbol before storing.
# @param [String, Symbol] name - The attribute name.
# @param [Object] value - The attribute value.
# @return [ContextConfig] self, allowing method chaining.
def set_attribute(name, value)
@attributes[name.to_sym] = value
self
Expand Down Expand Up @@ -73,4 +87,4 @@ def set_event_logger(event_logger)
@event_logger = event_logger
self
end
end
end
Loading