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
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/march_hare/metadata.rb', line 78 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
121 122 123 124 125 |
# File 'lib/march_hare/metadata.rb', line 121 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.
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/march_hare/metadata.rb', line 101 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 |