Skip to content

Instantly share code, notes, and snippets.

@theCrab
Created January 30, 2014 22:09
Show Gist options
  • Save theCrab/8721016 to your computer and use it in GitHub Desktop.
Save theCrab/8721016 to your computer and use it in GitHub Desktop.
How to implement the GitHub Orgs, Users, Repo Access Control Level using DataMapper.
class Organisation
include DataMapper::Resource
property :id, Serial
property :name, String, length: 3..15
timestamps :created_at, :updated_at
belongs_to :user
has n, :teams
has n, :users, through: :teams
end
class User
property :id, Serial
property :username, String
has n, :organisations
has n, :teams
end
class Team
## Team is used to manage vehicles
include DataMapper::Resource
property :id, Serial
property :name, String, required: true
property :permission, Enum[:owner, :garage, :driver, :dispatcher], default: :driver
belongs_to :organisation
has n, :members, class: 'User', child_key: :member_id
end
class Vehicle # On GitHub, this is similar to a Repository
include DataMapper::Resource
property :id, Serial
property :vin, String, required: true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment