Skip to content

Commit ddc4ecf

Browse files
committed
Have MemberPresenter return false to undefined methods
In order to use the MemberPresenter more flexibly, I want to remove the constant checking. The Presenter should be able to intialise with a `nil` object and then deal with the consequences of that. This approach will return `false` to any method not defined on the presenter or the presented object. Signed-off-by: jonathan.kerr <3410350+jonodrew@users.noreply.github.com>
1 parent 4ae2277 commit ddc4ecf

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

app/presenters/member_presenter.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
class MemberPresenter < BasePresenter
2+
include FalseResponder
23

34
def initialize(current_user)
45
@member = current_user

app/services/false_responder.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
module FalseResponder
4+
def method_missing(method_name, *args, &block)
5+
false
6+
end
7+
8+
def respond_to_missing?(method_name, include_private = false)
9+
true
10+
end
11+
end

0 commit comments

Comments
 (0)