Class: MarchHare::BasicPropertiesBuilder
- Inherits:
-
Object
- Object
- MarchHare::BasicPropertiesBuilder
- Defined in:
- lib/march_hare/metadata.rb
Class Method Summary collapse
- .build_properties_from(props = {}) ⇒ Object
- .deep_stringify_keys(hash) ⇒ Object
-
.transform_hash(value, options = {}, &block) ⇒ Object
Deep hash transformation fn is courtesy of Avdi Grimm and Markus Kuhnt, with some modifications to support primitive and array values.
Class Method Details
.build_properties_from(props = {}) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/march_hare/metadata.rb', line 100 def self.build_properties_from(props = {}) builder = AMQP::BasicProperties::Builder.new builder.content_type(props[:content_type]). content_encoding(props[:content_encoding]). headers(self.deep_stringify_keys(props[:headers])). delivery_mode(props[:persistent] ? 2 : 1). priority(props[:priority]). correlation_id(props[:correlation_id]). reply_to(props[:reply_to]). expiration(if props[:expiration] then props[:expiration].to_s end). (props[:message_id]). (props[:timestamp]). type(props[:type]). user_id(props[:user_id]). app_id(props[:app_id]). cluster_id(props[:cluster_id]). build end |
.deep_stringify_keys(hash) ⇒ Object
143 144 145 146 147 |
# File 'lib/march_hare/metadata.rb', line 143 def self.deep_stringify_keys(hash) transform_hash(hash, :deep => true) do |hash, key, value| hash[key.to_s] = value end end |
.transform_hash(value, options = {}, &block) ⇒ Object
Deep hash transformation fn is courtesy of Avdi Grimm and Markus Kuhnt, with some modifications to support primitive and array values.
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/march_hare/metadata.rb', line 123 def self.transform_hash(value, = {}, &block) return nil if value.nil? return value if !value.is_a?(Hash) && !value.is_a?(Array) return value.map { |v| transform_hash(v, , &block) } if value.is_a?(Array) value.inject({}) do |result, (key, value)| value = if ([:deep] && value.is_a?(Hash)) transform_hash(value, , &block) else if value.is_a?(Array) value.map { |v| transform_hash(v, , &block) } else value end end block.call(result, key, value) result end end |