Class: Doze::Resource::Proxy
- Inherits:
-
Object
- Object
- Doze::Resource::Proxy
- Includes:
- Doze::Resource
- Defined in:
- lib/doze/resource/proxy.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Attributes included from Doze::Resource
Instance Method Summary collapse
- #accepts_method_with_media_type?(resource_method, entity) ⇒ Boolean
-
#authorize(user, method) ⇒ Object
Some methods which should return something other than nil by default for an empty target:.
-
#initialize(uri, target) ⇒ Proxy
constructor
A new instance of Proxy.
- #other_method(method_name, entity = nil) ⇒ Object
-
#post(entity, session) ⇒ Object
proxying post is a bit fiddly due to the (in retrospect perhaps a bit unadvised) convenience support for different method arities for post.
- #supports_method?(method) ⇒ Boolean
-
#try(method, *args, &block) ⇒ Object
Methods based around use try / respond_to? need special care when proxying:.
Methods included from Doze::Resource
#cache_expiry_period, #cacheable?, #delete_resource, #exists?, #get, #last_modified, #public_cache_expiry_period, #publicly_cacheable?, #put, #supports_get?, #uri_object
Constructor Details
#initialize(uri, target) ⇒ Proxy
Returns a new instance of Proxy.
14 15 16 17 |
# File 'lib/doze/resource/proxy.rb', line 14 def initialize(uri, target) @uri = uri @target = target end |
Instance Attribute Details
#target ⇒ Object (readonly)
Returns the value of attribute target.
19 20 21 |
# File 'lib/doze/resource/proxy.rb', line 19 def target @target end |
Instance Method Details
#accepts_method_with_media_type?(resource_method, entity) ⇒ Boolean
48 49 50 51 52 53 54 55 |
# File 'lib/doze/resource/proxy.rb', line 48 def accepts_method_with_media_type?(resource_method, entity) method_name = "accepts_#{resource_method}_with_media_type?" if respond_to?(method_name) send(method_name, entity) else target && target.accepts_method_with_media_type?(resource_method, entity) end end |
#authorize(user, method) ⇒ Object
Some methods which should return something other than nil by default for an empty target:
71 72 73 |
# File 'lib/doze/resource/proxy.rb', line 71 def (user, method) target ? target.(user, method) : true end |
#other_method(method_name, entity = nil) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/doze/resource/proxy.rb', line 40 def other_method(method_name, entity=nil) if respond_to?(method_name) send(method_name, entity) else target && target.other_method(method_name, entity) end end |
#post(entity, session) ⇒ Object
proxying post is a bit fiddly due to the (in retrospect perhaps a bit unadvised) convenience support for different method arities for post. maybe move to post_with_session(entity, session) vs post(entity) if this causes any more pain.
60 61 62 63 64 65 66 67 |
# File 'lib/doze/resource/proxy.rb', line 60 def post(entity, session) t = target or return if t.method(:post).arity.abs > 1 t.post(entity, session) else t.post(entity) end end |
#supports_method?(method) ⇒ Boolean
31 32 33 34 35 36 37 38 |
# File 'lib/doze/resource/proxy.rb', line 31 def supports_method?(method) supports_method = "supports_#{method}?" if respond_to?(supports_method) send(supports_method) else target && target.supports_method?(method) end end |
#try(method, *args, &block) ⇒ Object
Methods based around use try / respond_to? need special care when proxying:
23 24 25 26 27 28 29 |
# File 'lib/doze/resource/proxy.rb', line 23 def try(method, *args, &block) if respond_to?(method) send(method, *args, &block) elsif target.respond_to?(method) target && target.send(method, *args, &block) end end |