Skip to content

Instantly share code, notes, and snippets.

@blumysden
Last active August 29, 2015 14:24
Show Gist options
  • Save blumysden/df727d5dea155747e233 to your computer and use it in GitHub Desktop.
Save blumysden/df727d5dea155747e233 to your computer and use it in GitHub Desktop.

Given

my_list = List.find(123)
my_list.list_asset = <Badcom::InteractiveAsset #213812831289>

When someone tries to access .list_asset do the following:

if my_list.scoop_asset_id == nil
  # do nothing
elsif my_list.scoop_asset_id != nil && my_list.list_asset.scoop_id == nil
  my_list.list_asset.scoop_id = scoop_asset_id
  # behind the scenes, Badcom::InteractiveAsset checks PAPI, and updates published_date, etc...
  my_list.update(interactive_asset: my_list.list_asset.to_h)
elsif my_list.list_asset.scoop_id != nil
  # do nothing BUT
  # behind the scenes, Badcom::InteractiveAsset should check to see if published_date is nil, and if so should check PAPI
  # and then
  if my_list.list_asset.has_changed?
    my_list.update(interactive_asset: my_list.list_asset.to_h)
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment