module Connectors class ProviderAccount < 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 provider_account provider, account c = Provider::ProviderFactory.get_account_class(provider) bson = collection.find({provider: provider, _id: account}).to_a.first raise RecordNotFound.new("Account '#{account}' for provider '#{provider}' not found") unless 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