Class: RailsInfo::ModelPresenter
- Inherits:
-
Presenter
show all
- Defined in:
- app/presenters/rails_info/model_presenter.rb
Instance Method Summary
collapse
Methods inherited from Presenter
#subject=
Constructor Details
#initialize(subject, options = {}) ⇒ ModelPresenter
Returns a new instance of ModelPresenter.
2
3
4
5
6
7
|
# File 'app/presenters/rails_info/model_presenter.rb', line 2
def initialize(subject, options = {})
super(subject, options)
@rails_info_model = ::RailsInfo::Model.new
@list = @rails_info_model.list
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class RailsInfo::Presenter
Instance Method Details
#count ⇒ Object
9
10
11
|
# File 'app/presenters/rails_info/model_presenter.rb', line 9
def count
@list.keys.length.inspect
end
|
#creately ⇒ Object
48
49
50
|
# File 'app/presenters/rails_info/model_presenter.rb', line 48
def creately
content_tag :pre, @list.keys.sort.map{|key| creately_for_model(key, @list[key]) }.join('')
end
|
#hash_tree(hash = nil, options = { parent: '' }) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'app/presenters/rails_info/model_presenter.rb', line 25
def hash_tree(hash = nil, options = { parent: '' })
options.assert_valid_keys(:parent)
hash ||= @list
parent = options[parent].to_s
content = ''
hash.keys.sort.each do |key|
value = hash[key]
if value.is_a?(Hash) && !value.empty?
sub_content = hash_tree(value, parent: parent.blank? ? key : parent + "::" + key)
sub_content = (key + @rails_info_model.associations(key, parent: parent) + " " + sub_content).html_safe
content += content_tag(:li, sub_content)
else
content += content_tag(:li, key + @rails_info_model.associations(key, parent: parent))
end
end
content_tag(:ul, content.html_safe)
end
|
#list ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
|
# File 'app/presenters/rails_info/model_presenter.rb', line 13
def list
if @list.none?
I18n.t('rails_info.data.index.no_models_found')
else
@list.map{|row_set| ::RailsInfo::Data::RowSetPresenter.new(subject, row_set: row_set) }.each do |row_set_presenter|
yield row_set_presenter
end
""
end
end
|