Sha256: c3278329f8b3e9fe4540706b8d6a3f40fb75d402224ca67d45be103d9048d850

Contents?: true

Size: 1.74 KB

Versions: 14

Compression:

Stored size: 1.74 KB

Contents

module Rhoconnect
  class App < Model
    field :name, :string
    set   :users, :string
    attr_reader :delegate
    validates_presence_of :name
    
    @@sources = []
    
    class << self
      def create(fields={})
        fields[:id] = fields[:name]
        begin
          require under_score(fields[:name])
        rescue Exception; end
        super(fields)
      end
    end
    
    def can_authenticate?
      # TODO: optimize it!
      self.delegate && self.delegate.singleton_methods.map(&:to_sym).include?(:authenticate)
    end

    def authenticate(login, password, session)
      if Rhoconnect.appserver
        auth_result = DynamicAdapter.authenticate(login,password)
      elsif self.delegate
        auth_result = self.delegate.authenticate(login, password, session) 
      end
      
      if auth_result
        login = auth_result if auth_result.is_a? String
        user = User.load(login) if User.is_exist?(login)
        if not user
          user = User.create(:login => login)
          users << user.id
        end
        return user
      end
    end
    
    def delegate
      @delegate.nil? ? Object.const_get(camelize(self.name)) : @delegate
    end
    
    def delete
      @@sources = []
      super
    end
    
    def delete_sources
      @@sources = []
    end
    
    def partition_sources(partition,user_id)
      names = []
      @@sources.each do |source|
        s = Source.load(source,{:app_id => self.name,
          :user_id => user_id})
        if s.partition == partition
          names << s.name
        end
      end
      names
    end
    
    def store_blob(obj,field_name,blob)
      self.delegate.send :store_blob, obj,field_name,blob
    end
        
    def sources
      @@sources.uniq! || @@sources
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
rhoconnect-3.1.1 lib/rhoconnect/app.rb
rhoconnect-3.1.0 lib/rhoconnect/app.rb
rhoconnect-3.1.0.beta2 lib/rhoconnect/app.rb
rhoconnect-3.1.0.beta1 lib/rhoconnect/app.rb
rhoconnect-3.0.6 lib/rhoconnect/app.rb
rhoconnect-3.0.5 lib/rhoconnect/app.rb
rhoconnect-3.0.4 lib/rhoconnect/app.rb
rhoconnect-3.0.3 lib/rhoconnect/app.rb
rhoconnect-3.0.2 lib/rhoconnect/app.rb
rhoconnect-3.0.1 lib/rhoconnect/app.rb
rhoconnect-3.0.0 lib/rhoconnect/app.rb
rhoconnect-3.0.0.rc1 lib/rhoconnect/app.rb
rhoconnect-3.0.0.beta3 lib/rhoconnect/app.rb
rhoconnect-3.0.0.beta1 lib/rhoconnect/app.rb