Class: RailsInfo::Data::ObjectPresenter

Inherits:
Presenter
  • Object
show all
Defined in:
app/presenters/rails_info/data/object_presenter.rb

Instance Method Summary collapse

Methods inherited from Presenter

#subject=

Constructor Details

#initialize(subject, options = {}) ⇒ ObjectPresenter

Returns a new instance of ObjectPresenter.



2
3
4
5
6
7
8
# File 'app/presenters/rails_info/data/object_presenter.rb', line 2

def initialize(subject, options = {})
  super(subject, options)
  
  options.assert_valid_keys(:object)
  
  @object = options[:object]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RailsInfo::Presenter

Instance Method Details

#rowObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/presenters/rails_info/data/object_presenter.rb', line 10

def row
  content =  :td, class: 'first' do
    check_box_tag "data[]", "#{object[:class].name};#{object['id']}", false, id: "#{object[:class].name.tableize}-#{object['id']}"
  end
  
  object[:class].columns.each do |column|
    value = object[column.name]
    
    if ['string', 'text'].include?(column.type.to_s)
      text = value.present? && value.length > 20 ? "#{value[0,20]}..." : value
      value =  :span, text, title: value
    end
      
    content +=  :td, value
  end
  
  content
end