Module: Biovision::Components::Base::EntityLinks

Included in:
Biovision::Components::BaseComponent
Defined in:
app/lib/biovision/components/base/entity_links.rb

Overview

Links for entities in context of current user

Instance Method Summary collapse

Instance Method Details

Parameters:

  • entity (ApplicationRecord)
  • scope (Symbol|String) (defaults to: '')


15
16
17
18
19
20
21
22
23
# File 'app/lib/biovision/components/base/entity_links.rb', line 15

def entity_link(entity, scope = '')
  prefix = i[admin my].include?(scope.to_sym) ? scope : 'world'
  message = "#{prefix}_url".to_sym
  if entity.respond_to?(message)
    entity.send(message)
  else
    rest_entity_link(entity, scope.to_sym)
  end
end

Parameters:

  • entity (ApplicationRecord)
  • scope (Symbol)


27
28
29
30
31
32
33
34
# File 'app/lib/biovision/components/base/entity_links.rb', line 27

def rest_entity_link(entity, scope)
  collection = "/#{scope}/#{entity.class.table_name}".gsub('//', '/')
  if entity.attributes.key?('uuid') && scope != :admin
    "#{collection}/#{entity.uuid}"
  else
    "#{collection}/#{entity.id}"
  end
end

Parameters:

  • entity (ApplicationRecord)


9
10
11
# File 'app/lib/biovision/components/base/entity_links.rb', line 9

def text_for_link(entity)
  entity.respond_to?(:text_for_link) ? entity.text_for_link : entity.id
end