v3: add subscription model

This commit is contained in:
Konstantin Haase 2015-04-17 12:16:11 +02:00
parent aeb5046298
commit 3680fcf389
6 changed files with 26 additions and 2 deletions

View File

@ -0,0 +1,9 @@
module Travis::API::V3
module Features
extend self
def use_subscriptions?
Models::Subscription.table_exists?
end
end
end

View File

@ -1,6 +1,5 @@
require 'gh' require 'gh'
module Travis::API::V3 module Travis::API::V3
class GitHub class GitHub
DEFAULT_OPTIONS = { DEFAULT_OPTIONS = {

View File

@ -3,5 +3,10 @@ module Travis::API::V3
has_many :memberships has_many :memberships
has_many :users, through: :memberships has_many :users, through: :memberships
has_many :repositories, as: :owner has_many :repositories, as: :owner
has_one :subscription, as: :owner
def subscription
super if Features.use_subscriptions?
end
end end
end end

View File

@ -0,0 +1,4 @@
module Travis::API::V3
class Models::Subscription < Model
end
end

View File

@ -4,13 +4,18 @@ module Travis::API::V3
has_many :permissions, dependent: :destroy has_many :permissions, dependent: :destroy
has_many :emails, dependent: :destroy has_many :emails, dependent: :destroy
has_many :tokens, dependent: :destroy has_many :tokens, dependent: :destroy
has_many :repositories, through: :permissions
has_many :organizations, through: :memberships has_many :organizations, through: :memberships
has_many :repositories, as: :owner
has_one :subscription, as: :owner
serialize :github_oauth_token, Extensions::EncryptedColumn.new(disable: true) serialize :github_oauth_token, Extensions::EncryptedColumn.new(disable: true)
def token def token
tokens.first_or_create.token tokens.first_or_create.token
end end
def subscription
super if Features.use_subscriptions?
end
end end
end end

View File

@ -15,6 +15,8 @@ class Travis::Console
end end
end end
V3 = Travis::API::V3
Travis::Api::App.setup Travis::Api::App.setup
console = Travis::Console.new console = Travis::Console.new
methods = Travis::Console.instance_methods - Object.instance_methods methods = Travis::Console.instance_methods - Object.instance_methods