Class: Alephant::Broker::Component

Inherits:
Object
  • Object
show all
Defined in:
lib/alephant/broker/component.rb

Constant Summary collapse

HEADER_PREFIX =
"head_"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(meta, data) ⇒ Component

Returns a new instance of Component.



15
16
17
18
19
20
21
22
23
# File 'lib/alephant/broker/component.rb', line 15

def initialize(meta, data)
  @id        = meta.id
  @batch_id  = meta.batch_id
  @options   = symbolize(meta.options || {})
  @content   = data[:content].force_encoding "UTF-8"
  @opts_hash = meta.opts_hash
  @data      = data
  @meta      = meta
end

Instance Attribute Details

#batch_idObject (readonly)

Returns the value of attribute batch_id.



11
12
13
# File 'lib/alephant/broker/component.rb', line 11

def batch_id
  @batch_id
end

#contentObject (readonly)

Returns the value of attribute content.



11
12
13
# File 'lib/alephant/broker/component.rb', line 11

def content
  @content
end

#idObject (readonly)

Returns the value of attribute id.



11
12
13
# File 'lib/alephant/broker/component.rb', line 11

def id
  @id
end

#optionsObject (readonly)

Returns the value of attribute options.



11
12
13
# File 'lib/alephant/broker/component.rb', line 11

def options
  @options
end

#opts_hashObject (readonly)

Returns the value of attribute opts_hash.



11
12
13
# File 'lib/alephant/broker/component.rb', line 11

def opts_hash
  @opts_hash
end

Instance Method Details

#content_typeObject



25
26
27
# File 'lib/alephant/broker/component.rb', line 25

def content_type
  headers["Content-Type"]
end

#headersObject



29
30
31
32
33
34
35
# File 'lib/alephant/broker/component.rb', line 29

def headers
  {
    "Content-Type" => data[:content_type].to_s
  }
    .merge(data[:headers] || {})
    .merge()
end

#statusObject



37
38
39
# File 'lib/alephant/broker/component.rb', line 37

def status
  data[:meta].key?("status") ? data[:meta]["status"] : 200
end