Class: RestEasy::Resource::MetaCollector

Inherits:
Object
  • Object
show all
Defined in:
lib/rest_easy/resource.rb

Instance Method Summary collapse

Constructor Details

#initializeMetaCollector

Returns a new instance of MetaCollector.



105
106
107
# File 'lib/rest_easy/resource.rb', line 105

def initialize
  @data = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



113
114
115
116
117
118
119
120
# File 'lib/rest_easy/resource.rb', line 113

def method_missing(name, *args)
  key = name.to_s
  if key.end_with?("=")
    @data[key.chomp("=").to_sym] = args.first
  else
    @data[name.to_sym]
  end
end

Instance Method Details

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Same reasoning as Meta#respond_to_missing? — a blanket true makes this claim Ruby's implicit protocol methods and hand them the nil from method_missing. @data is guarded for the same reason too: respond_to? must never raise, and Psych and Marshal both probe a bare allocation before it is initialised.

Returns:



133
134
135
136
137
138
# File 'lib/rest_easy/resource.rb', line 133

def respond_to_missing?(name, include_private = false)
  return true if SETTER_PATTERN.match?(name.to_s)
  return super unless @data

  @data.key?(name.to_sym) || super
end

#to_hObject



109
110
111
# File 'lib/rest_easy/resource.rb', line 109

def to_h
  @data
end