Sha256: 7d3bafe86d4da306bd91d58c83ac09acfaa4825a07f87e4c180b46c4bed78a8d

Contents?: true

Size: 1.32 KB

Versions: 33

Compression:

Stored size: 1.32 KB

Contents

module Rhosync
  class App < Model
    field :name, :string
    set   :users, :string
    set   :sources, :string
    attr_reader :delegate
    validates_presence_of :name
    
    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?
      self.delegate && self.delegate.singleton_methods.include?("authenticate")
    end

    def authenticate(login, password, session)
      if self.delegate && self.delegate.authenticate(login, password, session)
        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 partition_sources(partition,user_id)
      names = []
      sources.members.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
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
rhosync-2.1.16 lib/rhosync/app.rb
rhosync-2.1.15 lib/rhosync/app.rb
rhosync-2.1.14 lib/rhosync/app.rb
rhosync-2.1.13 lib/rhosync/app.rb
rhosync-2.1.12 lib/rhosync/app.rb
rhosync-2.1.11 lib/rhosync/app.rb
rhosync-2.1.10 lib/rhosync/app.rb
rhosync-2.1.7 lib/rhosync/app.rb
rhosync-2.1.6 lib/rhosync/app.rb
rhosync-2.1.3 lib/rhosync/app.rb
rhosync-2.1.2 lib/rhosync/app.rb
rhosync-2.1.1 lib/rhosync/app.rb
rhosync-2.1.0 lib/rhosync/app.rb
rhosync-2.1.0.beta.2 lib/rhosync/app.rb
rhosync-2.1.0.beta.1 lib/rhosync/app.rb
rhosync-2.0.9 lib/rhosync/app.rb
rhosync-2.0.8 lib/rhosync/app.rb
rhosync-2.0.7 lib/rhosync/app.rb
rhosync-2.0.6 lib/rhosync/app.rb
rhosync-2.0.5 lib/rhosync/app.rb