Class: Rubeetup::ResponseWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/rubeetup/response_wrapper.rb

Overview

Simple wrapper to allow the use of method missing in order provide fancier RequestResponse’s attributes access.

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ ResponseWrapper

Returns a new instance of ResponseWrapper.

Parameters:

  • data (Hash{Symbol=> ...})

    hash of response data



10
11
12
# File 'lib/rubeetup/response_wrapper.rb', line 10

def initialize(data)
  @hash = data
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object

It captures messages passed on this object, and only responds to messages for which the @hash can provide a non-nil value.



18
19
20
21
22
23
24
25
26
27
# File 'lib/rubeetup/response_wrapper.rb', line 18

def method_missing(name, *args)
  if name == :[]
    key = args.first
    @hash.include?(key) ? @hash[key] : super
  elsif @hash.include? name
    @hash[name]
  else
    super
  end
end