31 lines
698 B
Ruby
31 lines
698 B
Ruby
|
|
module Connectors
|
||
|
|
class ProviderAccounts < Base
|
||
|
|
|
||
|
|
include Helpers::InsertCommand,
|
||
|
|
Helpers::DeleteCommand
|
||
|
|
|
||
|
|
def initialize(db)
|
||
|
|
super(db)
|
||
|
|
end
|
||
|
|
|
||
|
|
def provider_accounts provider
|
||
|
|
c = Provider::ProviderFactory.get_account_class(provider)
|
||
|
|
collection.find({provider: provider}).to_a.map{|bson| c.build_from_bson(bson)}
|
||
|
|
end
|
||
|
|
|
||
|
|
def collection_name
|
||
|
|
'provider_accounts'
|
||
|
|
end
|
||
|
|
|
||
|
|
private
|
||
|
|
|
||
|
|
def model_from_bson(bson)
|
||
|
|
c = Provider::ProviderFactory.get_account_class(bson["provider"])
|
||
|
|
raise InvalidRecord.new "Invalid provider '#{bson["provider"]}' for account '#{bson["_id"]}'" if c.nil?
|
||
|
|
c.build_from_bson(bson)
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
end
|
||
|
|
|