Class: ActiveHistory::Event
- Inherits:
-
Object
- Object
- ActiveHistory::Event
- Defined in:
- lib/activehistory/event.rb
Instance Attribute Summary collapse
-
#actions ⇒ Object
Returns the value of attribute actions.
-
#regards ⇒ Object
Returns the value of attribute regards.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
Instance Method Summary collapse
- #action!(action) ⇒ Object
- #action_for(id) ⇒ Object
- #as_json ⇒ Object
- #encapsulate ⇒ Object
-
#initialize(attrs = {}) ⇒ Event
constructor
A new instance of Event.
- #regard!(regard) ⇒ Object
- #save! ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ Event
Returns a new instance of Event.
5 6 7 8 9 10 |
# File 'lib/activehistory/event.rb', line 5 def initialize(attrs={}) @attrs = attrs @attrs[:timestamp] ||= Time.now @actions = [] @regards = [] end |
Instance Attribute Details
#actions ⇒ Object
Returns the value of attribute actions.
3 4 5 |
# File 'lib/activehistory/event.rb', line 3 def actions @actions end |
#regards ⇒ Object
Returns the value of attribute regards.
3 4 5 |
# File 'lib/activehistory/event.rb', line 3 def regards @regards end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
3 4 5 |
# File 'lib/activehistory/event.rb', line 3 def @timestamp end |
Instance Method Details
#action!(action) ⇒ Object
12 13 14 15 16 |
# File 'lib/activehistory/event.rb', line 12 def action!(action) action = ActiveHistory::Action.new(action) @actions << action action end |
#action_for(id) ⇒ Object
18 19 20 |
# File 'lib/activehistory/event.rb', line 18 def action_for(id) @actions.find { |a| a.subject == id } end |
#as_json ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/activehistory/event.rb', line 32 def as_json { ip: @attrs[:ip], user_agent: @attrs[:user_agent], session_id: @attrs[:session_id], account: @attrs[:account], api_key: @attrs[:api_key], metadata: @attrs[:metadata], timestamp: @attrs[:timestamp].utc.iso8601(3), actions: @actions.map(&:as_json), regards: @regards.map(&:as_json) } end |
#encapsulate ⇒ Object
46 47 48 |
# File 'lib/activehistory/event.rb', line 46 def encapsulate ensure end |
#regard!(regard) ⇒ Object
22 23 24 |
# File 'lib/activehistory/event.rb', line 22 def regard!(regard) @regards << regard end |
#save! ⇒ Object
26 27 28 29 30 |
# File 'lib/activehistory/event.rb', line 26 def save! return if @actions.empty? ActiveHistory.connection.post('/events', self.as_json) end |