Skip to content

Commit

Permalink
Adding respond_to_missing? method in client
Browse files Browse the repository at this point in the history
  • Loading branch information
araluce committed Sep 17, 2024
1 parent a2fad7b commit ba0c576
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/calendlyr/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ def method_missing(method_name, *args, &block)
end
end

def respond_to_missing?(method_name, include_private = false)
resource_name = method_name.to_s.split("_").collect(&:capitalize).join + "Resource"

Calendlyr.const_defined?(resource_name) || super
end

# Avoid returning #<Calendlyr::Client @token="token" ...>
def inspect
"#<Calendlyr::Client>"
Expand Down
5 changes: 5 additions & 0 deletions test/calendlyr/client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ def test_method_missing
client.useers
end
end

def test_respond_to_missing?
assert client.respond_to?(:users)
refute client.respond_to?(:useers)
end
end

0 comments on commit ba0c576

Please sign in to comment.