Class: Dionysus::Consumer::Deserializer::SerializedRecord

Inherits:
Object
  • Object
show all
Defined in:
lib/dionysus/consumer/deserializer.rb

Instance Method Summary collapse

Constructor Details

#initialize(payload) ⇒ SerializedRecord

Returns a new instance of SerializedRecord.



157
158
159
# File 'lib/dionysus/consumer/deserializer.rb', line 157

def initialize(payload)
  @payload = payload
end

Instance Method Details

#canceled_atObject



193
194
195
# File 'lib/dionysus/consumer/deserializer.rb', line 193

def canceled_at
  payload["canceled_at"]
end

#created_atObject



185
186
187
# File 'lib/dionysus/consumer/deserializer.rb', line 185

def created_at
  payload["created_at"]
end

#expected_has_many_relationshipsObject



165
166
167
# File 'lib/dionysus/consumer/deserializer.rb', line 165

def expected_has_many_relationships
  to_many_foreign_keys.keys
end

#expected_has_one_relationshipsObject



169
170
171
# File 'lib/dionysus/consumer/deserializer.rb', line 169

def expected_has_one_relationships
  to_one_foreign_keys.keys
end

#has?(key) ⇒ Boolean

Returns:

  • (Boolean)


197
198
199
# File 'lib/dionysus/consumer/deserializer.rb', line 197

def has?(key)
  key?(key)
end

#has_canceled_at?Boolean

Returns:

  • (Boolean)


209
210
211
# File 'lib/dionysus/consumer/deserializer.rb', line 209

def has_canceled_at?
  has?("canceled_at")
end

#has_created_at?Boolean

Returns:

  • (Boolean)


201
202
203
# File 'lib/dionysus/consumer/deserializer.rb', line 201

def has_created_at?
  has?("created_at")
end

#has_updated_at?Boolean

Returns:

  • (Boolean)


205
206
207
# File 'lib/dionysus/consumer/deserializer.rb', line 205

def has_updated_at?
  has?("updated_at")
end

#idObject



181
182
183
# File 'lib/dionysus/consumer/deserializer.rb', line 181

def id
  payload["id"]
end


213
214
215
# File 'lib/dionysus/consumer/deserializer.rb', line 213

def links
  payload["links"].to_h
end

#model_name_for_relationship(relationship_name) ⇒ Object



173
174
175
176
177
178
179
# File 'lib/dionysus/consumer/deserializer.rb', line 173

def model_name_for_relationship(relationship_name)
  if polymorphic_relationship?(relationship_name) && links[relationship_name].key?("type")
    links[relationship_name]["type"]
  else
    relationship_name
  end
end

#plain_attributesObject



161
162
163
# File 'lib/dionysus/consumer/deserializer.rb', line 161

def plain_attributes
  payload.except(*RESERVED_ATTRIBUTES, *expected_has_many_relationships, *expected_has_one_relationships)
end

#updated_atObject



189
190
191
# File 'lib/dionysus/consumer/deserializer.rb', line 189

def updated_at
  payload["updated_at"]
end