Module: RocketPants::HeaderMetadata
- Defined in:
- lib/rocket_pants/controller/header_metadata.rb
Instance Method Summary collapse
- #build_header_hash(options, hash = {}, prefix = 'X-Api') ⇒ Object
-
#expose_metadata(metadata) ⇒ Hash{Symbol => Object}
Given a hash of request metadata, will: 1.
-
#metadata_headers(&blk) ⇒ Object
Given a block which returns a Hash, will call and merge the block iff header metadata is enabled.
Instance Method Details
#build_header_hash(options, hash = {}, prefix = 'X-Api') ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rocket_pants/controller/header_metadata.rb', line 24 def build_header_hash(, hash = {}, prefix = 'X-Api') .each_pair do |k, v| current = "#{prefix}-#{k.to_s.titleize.tr(" ", "-")}" if v.is_a?(Hash) build_header_hash v, hash, current else value = Array(v).join(", ") hash[current] = value if value.present? end end hash end |
#expose_metadata(metadata) ⇒ Hash{Symbol => Object}
Given a hash of request metadata, will:
-
Write out the headers for the current metadata
-
Return the hash, suitable for merging into the response hash
-
Start a dance party.
11 12 13 14 |
# File 'lib/rocket_pants/controller/header_metadata.rb', line 11 def () { build_header_hash() } super # Call any other versions of the method. end |
#metadata_headers(&blk) ⇒ Object
Given a block which returns a Hash, will call and merge the block iff header metadata is enabled. This is to avoid the overhead of generating headers on every request when it’s disabled.
20 21 22 |
# File 'lib/rocket_pants/controller/header_metadata.rb', line 20 def (&blk) headers.merge! blk.call if RocketPants. end |