Last active
June 18, 2019 23:05
-
-
Save watzon/933ea33bb474d3b3f46ac5434a652a2c to your computer and use it in GitHub Desktop.
Lucky Models
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Organization < BaseModel | |
table :organizations do | |
column name : String | |
column email : String | |
column profile_image_url : String? | |
column description : String? | |
column github_username : String? | |
column gitlab_username : String? | |
column twitter_username : String? | |
column website_url : String? | |
has_many organization_members : OrganizationMember | |
has_many members : User, through: :organization_members | |
end | |
def profile_photo | |
if profile_image = profile_image_url | |
profile_image | |
else | |
"https://placeimg.com/300/300/arch/grayscale" | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OrganizationMember < BaseModel | |
table :organization_members do | |
belongs_to user : User | |
belongs_to organization : Organization | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Shard < BaseModel | |
table :shards do | |
column name : String | |
column description : String? | |
column readme_content : String? | |
column spdx_license_identifier : String? | |
column license_url : String? | |
column license_content : String? | |
column repository_url : String | |
column repository_type : String | |
column documentation_url : String? | |
column bug_tracker_url : String? | |
column authors : String? | |
has_many downloads : ShardDownload | |
has_many versions : ShardVersion | |
column shardable_type : String | |
column shardable_id : Int32 | |
end | |
def shardable | |
if shardable_type == "organization" | |
OrganizationQuery.find(shardable_id) | |
elsif shardable_type == "user" | |
UserQuery.find(shardable_id) | |
else | |
raise "Unexpected shardable_type: #{shardable_type}" | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ShardDownload < BaseModel | |
# Use ipstack for getting info about the user | |
table :shard_downloads do | |
column ip_columnress : String | |
column user_agent : String | |
column continent_code : String? | |
column continent_name : String? | |
column country_code : String? | |
column country_name : String? | |
column region_code : String? | |
column region_name : String? | |
column city : String? | |
column zip : Int32? | |
column time_zone : String? | |
column time_zone_code : String? | |
column isp : String? | |
column proxied : Bool? | |
column crawler : Bool? | |
column crawler_name : String? | |
column crawler_type : String? | |
column tor : Bool? | |
belongs_to user : User? | |
belongs_to shard_version : ShardVersion | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ShardVersion < BaseModel | |
table :shard_versions do | |
column name : String | |
column ghid : Int32 | |
column node_id : String | |
column url : String | |
column description : String? | |
column prerelease : Bool | |
column published_at : Time | |
column tarball_url : String | |
belongs_to shard : Shard | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < BaseModel | |
include Carbon::Emailable | |
include Authentic::PasswordAuthenticatable | |
table :users do | |
column email : String | |
column username : String | |
column full_name : String? | |
column encrypted_password : String | |
column github_username : String? | |
column gitlab_username : String? | |
column twitter_username : String? | |
column personal_website : String? | |
column newsletter : Bool = false | |
column superuser : Bool? | |
has_many organization_members : OrganizationMember | |
has_many organizations : Organization, through: :organization_members | |
end | |
def is_superuser? | |
@superuser | |
end | |
def profile_photo | |
GravatarHelper.gravatar_for_email(email) | |
end | |
def emailable | |
Carbon::Address.new(email) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Error: