Class: ActiveHistory::Action

Inherits:
Object
  • Object
show all
Defined in:
lib/activehistory/action.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs) ⇒ Action

Returns a new instance of Action.



5
6
7
8
9
10
# File 'lib/activehistory/action.rb', line 5

def initialize(attrs)
  attrs.each do |k,v|
    self.send("#{k}=", v)
  end
  self.diff ||= {}
end

Instance Attribute Details

#diffObject

Returns the value of attribute diff.



3
4
5
# File 'lib/activehistory/action.rb', line 3

def diff
  @diff
end

#event_idObject

Returns the value of attribute event_id.



3
4
5
# File 'lib/activehistory/action.rb', line 3

def event_id
  @event_id
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/activehistory/action.rb', line 3

def id
  @id
end

#subject_idObject

Returns the value of attribute subject_id.



3
4
5
# File 'lib/activehistory/action.rb', line 3

def subject_id
  @subject_id
end

#subject_typeObject

Returns the value of attribute subject_type.



3
4
5
# File 'lib/activehistory/action.rb', line 3

def subject_type
  @subject_type
end

#timestampObject

Returns the value of attribute timestamp.



3
4
5
# File 'lib/activehistory/action.rb', line 3

def timestamp
  @timestamp
end

#typeObject

Returns the value of attribute type.



3
4
5
# File 'lib/activehistory/action.rb', line 3

def type
  @type
end

Instance Method Details

#as_jsonObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/activehistory/action.rb', line 12

def as_json
  {
    diff:         diff.as_json,
    subject_type: subject_type,
    subject_id:   subject_id,
    timestamp:    timestamp.iso8601(3),
    type:         type,
    event_id:     event_id,
    id:           id
  }.select { |k, v| !v.nil? }
end