Class: NodeInfoPresenter
- Inherits:
-
Object
- Object
- NodeInfoPresenter
- Defined in:
- app/presenters/node_info_presenter.rb
Instance Method Summary collapse
- #add_configuration(doc) ⇒ Object
- #add_static_data(doc) ⇒ Object
- #add_usage(doc) ⇒ Object
- #add_user_counts(doc) ⇒ Object
- #admin_account ⇒ Object
- #available_services ⇒ Object
- #camo_config ⇒ Object
- #document ⇒ Object
- #expose_comment_counts? ⇒ Boolean
- #expose_posts_counts? ⇒ Boolean
- #expose_user_counts? ⇒ Boolean
- #halfyear_users ⇒ Object
-
#initialize(version) ⇒ NodeInfoPresenter
constructor
A new instance of NodeInfoPresenter.
- #local_comments ⇒ Object
- #local_posts ⇒ Object
- #monthly_users ⇒ Object
- #name ⇒ Object
- #open_registrations? ⇒ Boolean
- #total_users ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(version) ⇒ NodeInfoPresenter
Returns a new instance of NodeInfoPresenter.
6 7 8 |
# File 'app/presenters/node_info_presenter.rb', line 6 def initialize(version) @version = version end |
Instance Method Details
#add_configuration(doc) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'app/presenters/node_info_presenter.rb', line 21 def add_configuration(doc) doc.software.version = version doc.services.outbound = available_services doc.open_registrations = open_registrations? doc.["nodeName"] = name doc.["camo"] = camo_config doc.["adminAccount"] = admin_account end |
#add_static_data(doc) ⇒ Object
30 31 32 33 34 35 |
# File 'app/presenters/node_info_presenter.rb', line 30 def add_static_data(doc) doc.software.name = "diaspora" doc.software.repository = "https://github.com/diaspora/diaspora" doc.software.homepage = "https://diasporafoundation.org/" doc.protocols.protocols << "diaspora" end |
#add_usage(doc) ⇒ Object
45 46 47 48 |
# File 'app/presenters/node_info_presenter.rb', line 45 def add_usage(doc) doc.local_posts = local_posts if expose_posts_counts? doc.local_comments = local_comments if expose_comment_counts? end |
#add_user_counts(doc) ⇒ Object
37 38 39 40 41 42 43 |
# File 'app/presenters/node_info_presenter.rb', line 37 def add_user_counts(doc) return unless expose_user_counts? doc.total = total_users doc.active_halfyear = halfyear_users doc.active_month = monthly_users end |
#admin_account ⇒ Object
82 83 84 |
# File 'app/presenters/node_info_presenter.rb', line 82 def admin_account AppConfig.admins.account if AppConfig.admins.account? end |
#available_services ⇒ Object
86 87 88 89 90 |
# File 'app/presenters/node_info_presenter.rb', line 86 def available_services Configuration::KNOWN_SERVICES.select {|service| AppConfig.show_service?(service, nil) }.map(&:to_s) end |
#camo_config ⇒ Object
74 75 76 77 78 79 80 |
# File 'app/presenters/node_info_presenter.rb', line 74 def camo_config { markdown: AppConfig.privacy.camo.proxy_markdown_images?, opengraph: AppConfig.privacy.camo.proxy_opengraph_thumbnails?, remotePods: AppConfig.privacy.camo.proxy_remote_pod_images? } end |
#document ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'app/presenters/node_info_presenter.rb', line 10 def document @document ||= NodeInfo.build do |doc| doc.version = @version add_static_data doc add_configuration doc add_user_counts doc.usage.users add_usage doc.usage end end |
#expose_comment_counts? ⇒ Boolean
58 59 60 |
# File 'app/presenters/node_info_presenter.rb', line 58 def expose_comment_counts? AppConfig.privacy.statistics.comment_counts? end |
#expose_posts_counts? ⇒ Boolean
54 55 56 |
# File 'app/presenters/node_info_presenter.rb', line 54 def expose_posts_counts? AppConfig.privacy.statistics.post_counts? end |
#expose_user_counts? ⇒ Boolean
50 51 52 |
# File 'app/presenters/node_info_presenter.rb', line 50 def expose_user_counts? AppConfig.privacy.statistics.user_counts? end |
#halfyear_users ⇒ Object
100 101 102 |
# File 'app/presenters/node_info_presenter.rb', line 100 def halfyear_users @halfyear_users ||= User.halfyear_actives.count end |
#local_comments ⇒ Object
113 114 115 116 117 118 119 |
# File 'app/presenters/node_info_presenter.rb', line 113 def local_comments Rails.cache.fetch("NodeInfoPresenter/local_comments", expires_in: 1.hour) do @local_comments ||= Comment.joins(:author) .where.not(people: {owner_id: nil}) .count end end |
#local_posts ⇒ Object
104 105 106 107 108 109 110 111 |
# File 'app/presenters/node_info_presenter.rb', line 104 def local_posts Rails.cache.fetch("NodeInfoPresenter/local_posts", expires_in: 1.hour) do @local_posts ||= Post.where(type: "StatusMessage") .joins(:author) .where.not(people: {owner_id: nil}) .count end end |
#monthly_users ⇒ Object
96 97 98 |
# File 'app/presenters/node_info_presenter.rb', line 96 def monthly_users @monthly_users ||= User.monthly_actives.count end |
#name ⇒ Object
62 63 64 |
# File 'app/presenters/node_info_presenter.rb', line 62 def name AppConfig.settings.pod_name end |
#open_registrations? ⇒ Boolean
70 71 72 |
# File 'app/presenters/node_info_presenter.rb', line 70 def open_registrations? AppConfig.settings.enable_registrations? end |
#total_users ⇒ Object
92 93 94 |
# File 'app/presenters/node_info_presenter.rb', line 92 def total_users @total_users ||= User.active.count end |
#version ⇒ Object
66 67 68 |
# File 'app/presenters/node_info_presenter.rb', line 66 def version AppConfig.version_string end |