Class: RestCore::Defaults
- Inherits:
-
Object
- Object
- RestCore::Defaults
- Includes:
- Middleware
- Defined in:
- lib/rest-core/middleware/defaults.rb
Constant Summary
Constants included from Middleware
Constants included from RestCore
ASYNC, CLIENT, DRY, FAIL, HIJACK, LOG, PROMISE, REQUEST_HEADERS, REQUEST_METHOD, REQUEST_PATH, REQUEST_PAYLOAD, REQUEST_QUERY, REQUEST_URI, RESPONSE_BODY, RESPONSE_HEADERS, RESPONSE_KEY, RESPONSE_SOCKET, RESPONSE_STATUS, Simple, TIMER, Universal, VERSION
Class Method Summary collapse
Instance Method Summary collapse
-
#method_missing(msg, *args, &block) ⇒ Object
the use of singleton_class is making serialization hard! def initialize app, defaults super singleton_class.module_eval do defaults.each{ |(key, value)| define_method(key) do |env| if value.respond_to?(:call) value.call else value end end } end end.
- #respond_to_missing?(msg, include_private = false) ⇒ Boolean
Methods included from Middleware
#call, #contain_binary?, contain_binary?, #escape, escape, #fail, #id, included, #log, merge_hash, #merge_hash, #percent_encode, percent_encode, #request_uri, request_uri, #run, #string_keys, string_keys
Methods included from RestCore
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(msg, *args, &block) ⇒ Object
the use of singleton_class is making serialization hard! def initialize app, defaults
super
singleton_class.module_eval do
defaults.each{ |(key, value)|
define_method(key) do |env|
if value.respond_to?(:call)
value.call
else
value
end
end
}
end
end
24 25 26 27 28 29 30 31 |
# File 'lib/rest-core/middleware/defaults.rb', line 24 def method_missing msg, *args, &block env = args.first if env.kind_of?(Hash) && (d = defaults(env)) && d.key?(msg) defaults(env)[msg] else super end end |
Class Method Details
.members ⇒ Object
5 |
# File 'lib/rest-core/middleware/defaults.rb', line 5 def self.members; [:defaults]; end |
Instance Method Details
#respond_to_missing?(msg, include_private = false) ⇒ Boolean
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rest-core/middleware/defaults.rb', line 33 def respond_to_missing? msg, include_private=false # since psych would call respond_to? before setting up # instance variables when restoring ruby objects, we might # be accessing undefined ivars in that case even all ivars are # defined in initialize. we can't avoid this because we can't # use singleton_class (otherwise we can't serialize this) return super unless instance_variable_defined?(:@defaults) if (d = defaults({})) && d.key?(msg) true else super end end |