Repository is archived
No release in over a year
Obscured::Timeline is a Mongoid extension adds events to a separate collection for an entity (e.g. User), the naming of the class (Mongoid Document) is used for naming the timeline collection, so if the class is named "Account" the collection name will end up being "account_timeline".
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

Build Status Vulnerabilities Gem Version Test Coverage Code Climate

Obscured::Timeline

Introduction

Obscured timeline adds event to a separate collection for an entity (Document), the naming of the class (Mongoid Document) is used for naming the timeline collection, so if the class is named "Account" the collection name will end up being "account_timeline".

Installation

Requirements

  • activesupport
  • mongoid
  • mongoid_search
Add this line to your application's Gemfile
gem 'obscured-timeline'
Execute
$ bundle

Usage

Base

Use this in files where you create non-default log collections.

require 'obscured-timeline'

Example

Document

require 'obscured-timeline'

module Obscured
  class Account
    include Mongoid::Document
    include Mongoid::Timestamps
    include Obscured::Timeline::Tracker
    
    field :name, type: String
    field :email, type: String
    field :locked, type: Boolean, default: false
  end

  def lock!
    self.locked = true
    self.add_event(type: :security, message: "Account has been locked!", producer: self.username)
    save
  end
end


account = Obscured::Account.create(:name => "John Doe", :email => "john.doe@obscured.se")
event = account.add_event(type: :comment, message: "Lorem ipsum dolor sit amet?", producer: "homer.simpson@obscured.se")

#returns array of events for document (proprietor)
account.get_events 

#returns event by id
account.get_event(event.id.to_s)

#returns array of events by predefined params, supports pagination
account.find_events({ type: nil, producer: nil }, { limit: 20, skip: 0, order: :created_at.desc, only: [:id, :type, :message, :producer, :created_at, :updated_at, :proprietor] })

#retuns array of events
account.search_events("homer.simpson@obscured.se", { type: :comment, limit: 20, skip: 0, order: :created_at.desc }) 

Service

module Obscured
  class AccountTimelineService
    include Obscured::Timeline::Service::Base
  end
end

module Obscured
  class AccountSynchronizer
    def initialize(account)
      @account = account
      @service = Obscured::AccountTimelineService.new
    end

    def timeline
      @service.by(proprietor: { account_id: account.id })
    end
  end
end