Skip to content

Instantly share code, notes, and snippets.

@krisleech
Created January 13, 2015 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krisleech/fef5fcb05a0ecaae5f45 to your computer and use it in GitHub Desktop.
Save krisleech/fef5fcb05a0ecaae5f45 to your computer and use it in GitHub Desktop.

Data referenced in code

Sometimes data is referenced in code, for example a dynamically created "tab" has a key (it's unique id).

If we want to fetch that tab in our code, we do Tab.find_by_key('organisations'). This will break if a user deletes this tab.

Locking some fields of an entity should solve this.

EntityLock(entity_class, entity_uuid, attributes, reason)

EntityLock.lock(entity)
EntityLock.lock(entity, [key, name])
EntityLock.locked?(entity)
EntityLock.locked?(entity, for: attributes)

# attributes can be an array or hash (keys will be taken).

The entity would not know about locking and it would be up to a repository or service object to check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment