Class: Adminable::Presenters::Entry

Inherits:
Base
  • Object
show all
Defined in:
lib/adminable/presenters/entry.rb

Instance Method Summary collapse

Constructor Details

#initialize(entry) ⇒ Entry

Returns a new instance of Entry.



4
5
6
# File 'lib/adminable/presenters/entry.rb', line 4

def initialize(entry)
  @entry = entry
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



60
61
62
# File 'lib/adminable/presenters/entry.rb', line 60

def method_missing(method_name, *args, &block)
  entry.public_send(method_name, *args, &block)
end

Instance Method Details



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/adminable/presenters/entry.rb', line 28

def link_to_delete
  view.link_to(
    I18n.t('adminable.buttons.delete'),
    polymorphic_path(@entry),
    class: 'btn btn-danger-outline pull-xs-right',
    method: :delete,
    data: {
      confirm: I18n.t('adminable.ui.confirm')
    }
  )
end


48
49
50
51
52
53
54
55
56
57
58
# File 'lib/adminable/presenters/entry.rb', line 48

def link_to_delete_small
  view.link_to(
    I18n.t('adminable.buttons.delete'),
    polymorphic_path(entry),
    class: 'label label-danger',
    method: :delete,
    data: {
      confirm: I18n.t('adminable.ui.confirm')
    }
  )
end


40
41
42
43
44
45
46
# File 'lib/adminable/presenters/entry.rb', line 40

def link_to_edit_small
  view.link_to(
    I18n.t('adminable.buttons.edit'),
    edit_polymorphic_path(entry),
    class: 'label label-primary'
  )
end


18
19
20
21
22
23
24
25
26
# File 'lib/adminable/presenters/entry.rb', line 18

def link_to_self
  return to_name unless resource

  view.link_to(
    to_name,
    edit_polymorphic_path(entry),
    target: '_blank'
  )
end

#respond_to_missing?(method_name) ⇒ Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/adminable/presenters/entry.rb', line 64

def respond_to_missing?(method_name, *)
  entry.respond_to?(method_name)
end

#to_nameObject



8
9
10
11
12
13
14
15
16
# File 'lib/adminable/presenters/entry.rb', line 8

def to_name
  %i(name title email login id).each do |method_name|
    begin
      return entry.public_send(method_name)
    rescue NoMethodError
      next
    end
  end
end