Class: Bricolage::SQSMock::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/bricolage/sqsmock.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message_id: nil, receipt_handle: nil, body: nil) ⇒ Message

Returns a new instance of Message.



172
173
174
175
176
177
# File 'lib/bricolage/sqsmock.rb', line 172

def initialize(message_id: nil, receipt_handle: nil, body: nil)
  @message_id = message_id
  @receipt_handle = receipt_handle
  @body = body
  @body_json = { Records: [body] }.to_json
end

Instance Attribute Details

#message_idObject (readonly)

Returns the value of attribute message_id.



179
180
181
# File 'lib/bricolage/sqsmock.rb', line 179

def message_id
  @message_id
end

#receipt_handleObject (readonly)

Returns the value of attribute receipt_handle.



180
181
182
# File 'lib/bricolage/sqsmock.rb', line 180

def receipt_handle
  @receipt_handle
end

Class Method Details

.new_seqObject



158
159
160
161
# File 'lib/bricolage/sqsmock.rb', line 158

def Message.new_seq
  @seq += 1
  @seq
end

.s3_object_created_event(url) ⇒ Object



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/bricolage/sqsmock.rb', line 132

def Message.s3_object_created_event(url)
  raise "is not a S3 URL: #{url.inspect}" unless %r<\As3://\w> =~ url
  bucket, key = url.sub(%r<s3://>, '').split('/', 2)
  with_body({
    eventVersion: '2.0',
    eventSource: 'aws:s3',
    awsRegion: 'ap-northeast-1',
    eventTime: Time.now.iso8601,
    eventName: 'ObjectCreated:Put',
    s3: {
      s3SchemaVersion: '1.0',
      configurationId: 'TestConfig',
      bucket: {
        name: bucket,
        arn: "arn:aws:s3:::#{bucket}"
      },
      object: {
        key: key,
        size: 1024
      }
    }
  })
end

.with_body(body) ⇒ Object



163
164
165
166
167
168
169
170
# File 'lib/bricolage/sqsmock.rb', line 163

def Message.with_body(body)
  seq = new_seq
  new(
    message_id: "sqs-message-id-#{seq}",
    receipt_handle: "sqs-receipt-handle-#{seq}",
    body: body
  )
end

Instance Method Details

#bodyObject



182
183
184
# File 'lib/bricolage/sqsmock.rb', line 182

def body
  @body_json
end

#body_objectObject

for debug



187
188
189
# File 'lib/bricolage/sqsmock.rb', line 187

def body_object
  @body
end