Class: Integral::VersionDecorator

Inherits:
Draper::Decorator
  • Object
show all
Defined in:
app/decorators/integral/version_decorator.rb

Overview

Page view-level logic

Instance Method Summary collapse

Instance Method Details

#attributes_changedString

Returns formatted attributes changed.

Returns:

  • (String)

    formatted attributes changed



46
47
48
49
50
51
52
53
54
55
# File 'app/decorators/integral/version_decorator.rb', line 46

def attributes_changed
  return unless object.event == 'update'
  keys = ''

  object.changeset.each_key do |key|
    # next if ['updated_at', 'lock_version'].include? key
    keys += "#{key}, "
  end
  keys[0..-3]
end

#decorated_itemObject

Returns Associated Item.

Returns:

  • (Object)

    Associated Item



36
37
38
# File 'app/decorators/integral/version_decorator.rb', line 36

def decorated_item
  @decorated_item ||= item&.decorate
end

#eventString

Returns formatted event.

Returns:

  • (String)

    formatted event



12
13
14
# File 'app/decorators/integral/version_decorator.rb', line 12

def event
  h.t("integral.actions.#{object.event}")
end

#item_titleString

Returns formatted title.

Returns:

  • (String)

    formatted title



31
32
33
# File 'app/decorators/integral/version_decorator.rb', line 31

def item_title
  decorated_item&.title
end

#item_typeString

Returns formatted item type.

Returns:

  • (String)

    formatted item type



41
42
43
# File 'app/decorators/integral/version_decorator.rb', line 41

def item_type
  object.item_type.constantize.model_name.human
end

#item_urlString

Returns Item URL.

Returns:

  • (String)

    Item URL



17
18
19
# File 'app/decorators/integral/version_decorator.rb', line 17

def item_url
  decorated_item&.backend_url
end

#urlString

Returns URL to view version screen.

Returns:

  • (String)

    URL to view version screen



7
8
9
# File 'app/decorators/integral/version_decorator.rb', line 7

def url
  decorated_item&.activity_url(object.id)
end

#whodunnitIntegral::User

Returns who carried out the version (if one exists).

Returns:



22
23
24
25
26
27
28
# File 'app/decorators/integral/version_decorator.rb', line 22

def whodunnit
  user_id = object.whodunnit.to_i

  return '' if user_id.zero?

  @user = Integral::User.unscoped.find_by_id(object.whodunnit)&.decorate
end