Sha256: 3721473a9be8a7f1564f7a29092c5cc1b617774284bffdff050fd7a698437c0c

Contents?: true

Size: 796 Bytes

Versions: 4

Compression:

Stored size: 796 Bytes

Contents

module ActivityFeed
  module Custom
    class Item
      attr_accessor :user_id
      attr_accessor :nickname
      attr_accessor :type
      attr_accessor :title
      attr_accessor :text
      attr_accessor :url
      attr_accessor :icon
      attr_accessor :sticky

      def initialize(attributes = {})
        @attributes = attributes

        attributes.each do |key,value|
          self.send("#{key}=", value)
        end      
      end
      
      def attributes
        @attributes
      end

      def self.find(item)
        JSON.parse(item)
      end

      def save
        raise 'user_id MUST be defined in the attributes' if user_id.blank?

        ActivityFeed.redis.zadd(ActivityFeed.feed_key(self.user_id), DateTime.now.to_i, @attributes.to_json)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
activity_feed-1.4.0 spec/activity_feed/custom/item.rb
activity_feed-1.3.0 spec/activity_feed/custom/item.rb
activity_feed-1.2.1 spec/activity_feed/custom/item.rb
activity_feed-1.2 spec/activity_feed/custom/item.rb