Sha256: 7e1418a3b92494ff5600bab50a91ba2b7c9a365419644e7b2d4dcf111193da50

Contents?: true

Size: 1.23 KB

Versions: 2

Compression:

Stored size: 1.23 KB

Contents

module DCA
  module Redis
    class Session < Ohm::Model
      attribute :uid
      attribute :created
      attribute :project
      attribute :area

      index :uid
      index :project
      index :area

      set :analyzed, DCA::Redis::AnalyzeNotify
      set :fetched, DCA::Redis::FetchNotify
      set :failures, DCA::Redis::FailureNotify

      def validate
        assert_present :uid
      end

      def analyze_state state
        self.analyzed.find(:state => state).first
      end

      def fetch_state state
        self.fetched.find(:state => state).first
      end

      def inc_analyze state
        notify = self.analyzed.find(:state => state).first
        if notify.nil?
          notify = AnalyzeNotify.create(:state => state)
          self.analyzed.add notify
        end
        notify.incr :count
      end

      def inc_fetch state, result
        notify = self.fetched.find(:state => state).first
        if notify.nil?
          notify = FetchNotify.create(:state => state)
          self.fetched.add notify
        end
        notify.incr result
      end

      def add_failure exception
        self.failures.add FailureNotify.create(:message => exception.message, :stack => exception.backtrace)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dca-0.1.1 lib/dca/notifier/redis/models/session.rb
dca-0.1.0 lib/dca/notifier/redis/models/session.rb